summaryrefslogtreecommitdiff
path: root/src/corefx
diff options
context:
space:
mode:
Diffstat (limited to 'src/corefx')
-rw-r--r--src/corefx/System.Globalization.Native/pal_collation.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/corefx/System.Globalization.Native/pal_collation.c b/src/corefx/System.Globalization.Native/pal_collation.c
index a8c94cfb71..b8d451730d 100644
--- a/src/corefx/System.Globalization.Native/pal_collation.c
+++ b/src/corefx/System.Globalization.Native/pal_collation.c
@@ -439,11 +439,15 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti
TCollatorMap* map = (TCollatorMap*)malloc(sizeof(TCollatorMap));
map->key = options;
- void* entry = tsearch(map, &pSortHandle->collatorsPerOptionRoot, TreeComparer);
- if ((*(TCollatorMap**)entry) == map)
+ // tfind on glibc is significantly faster than tsearch and we expect
+ // to hit the cache here often so it's benefitial to prefer lookup time
+ // over addition time
+ void* entry = tfind(map, &pSortHandle->collatorsPerOptionRoot, TreeComparer);
+ if (entry == NULL)
{
pCollator = CloneCollatorWithOptions(pSortHandle->regular, options, pErr);
map->UCollator = pCollator;
+ tsearch(map, &pSortHandle->collatorsPerOptionRoot, TreeComparer);
}
else
{