Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/corefx/System.Globalization.Native/pal_collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ typedef struct { int32_t key; UCollator* UCollator; } TCollatorMap;
struct SortHandle
{
UCollator* regular;
TCollatorMap* collatorsPerOption;
pthread_mutex_t collatorsLockObject;
void* pRoot;
void* collatorsPerOptionRoot;
};

typedef struct { UChar* items; size_t capacity; size_t size; } UCharList;
Expand Down Expand Up @@ -372,7 +371,7 @@ void CreateSortHandle(SortHandle** ppSortHandle)
return;
}

(*ppSortHandle)->pRoot = NULL;
(*ppSortHandle)->collatorsPerOptionRoot = NULL;
int result = pthread_mutex_init(&(*ppSortHandle)->collatorsLockObject, NULL);

if (result != 0)
Expand Down Expand Up @@ -410,10 +409,10 @@ void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle)
ucol_close(pSortHandle->regular);
pSortHandle->regular = NULL;

while (pSortHandle->pRoot != NULL)
while (pSortHandle->collatorsPerOptionRoot != NULL)
{
TCollatorMap* data = *(TCollatorMap **)pSortHandle->pRoot;
tdelete(data, &pSortHandle->pRoot, TreeComparer);
TCollatorMap* data = *(TCollatorMap **)pSortHandle->collatorsPerOptionRoot;
tdelete(data, &pSortHandle->collatorsPerOptionRoot, TreeComparer);
ucol_close(data->UCollator);
free(data);
}
Expand All @@ -440,12 +439,11 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti

TCollatorMap* map = (TCollatorMap*)malloc(sizeof(TCollatorMap));
map->key = options;
void* entry = tfind(map, &pSortHandle->pRoot, TreeComparer);
if (entry == NULL)
void* entry = tsearch(map, &pSortHandle->collatorsPerOptionRoot, TreeComparer);
if ((*(TCollatorMap**)entry) == map)
{
pCollator = CloneCollatorWithOptions(pSortHandle->regular, options, pErr);
map->UCollator = pCollator;
tsearch(map, &pSortHandle->pRoot, TreeComparer);
}
else
{
Expand Down