From 0ca6b8978a894a1eda5322427af640b31406f750 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 19 Apr 2019 15:07:47 +0200 Subject: Fix performance regression on glibc on Linux (#24099) --- src/corefx/System.Globalization.Native/pal_collation.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/corefx') 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 { -- cgit v1.2.3