Skip to content

Commit

Permalink
Fix performance regression on glibc on Linux (dotnet/coreclr#24099)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@0ca6b89
  • Loading branch information
filipnavara authored and stephentoub committed Apr 19, 2019
1 parent c1222d0 commit 77034d8
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -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
{
Expand Down

0 comments on commit 77034d8

Please sign in to comment.