summaryrefslogtreecommitdiff
path: root/src/corefx
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-04-19 15:07:47 +0200
committerStephen Toub <stoub@microsoft.com>2019-04-19 09:07:47 -0400
commit0ca6b8978a894a1eda5322427af640b31406f750 (patch)
tree4e9158a617da533d1712d528a3c40405d447d21d /src/corefx
parentb7167889bc94c084527f184f852b867b2a1c1d56 (diff)
downloadcoreclr-0ca6b8978a894a1eda5322427af640b31406f750.tar.gz
coreclr-0ca6b8978a894a1eda5322427af640b31406f750.tar.bz2
coreclr-0ca6b8978a894a1eda5322427af640b31406f750.zip
Fix performance regression on glibc on Linux (#24099)
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
{