MCPcopy Create free account
hub / github.com/documentdb/documentdb / LookupUCollatorCache

Function LookupUCollatorCache

pg_documentdb_core/src/collation/collation.c:885–934  ·  view source on GitHub ↗

* Cache that live the lifetime of a backend process and caches a Ucollator object for performing * collation related operations. Open a collator object can be expensive and hence we create this cache. * When the backend process dies all memory associated with the collator cache is cleaned up. * * This is inspired by lookup_collation_cache() in pg_locale.c */

Source from the content-addressed store, hash-verified

883 * This is inspired by lookup_collation_cache() in pg_locale.c
884 */
885static ucollator_cache_entry *
886LookupUCollatorCache(const char *collationString)
887{
888 ucollator_cache_entry *cache_entry;
889 bool found;
890
891 if (collation_cache == NULL)
892 {
893 /* First time through, initialize the hash table */
894 HASHCTL ctl;
895 memset(&ctl, 0, sizeof(ctl));
896
897 ctl.keysize = sizeof(char *);
898 ctl.entrysize = sizeof(ucollator_cache_entry);
899
900 MemoryContext tempContext = AllocSetContextCreate(CurrentMemoryContext,
901 "Collation Context",
902 ALLOCSET_DEFAULT_SIZES);
903
904 MemoryContext oldContext = MemoryContextSwitchTo(tempContext);
905 collation_cache = hash_create("Collator cache", 100, &ctl,
906 HASH_ELEM | HASH_BLOBS);
907 MemoryContextSwitchTo(oldContext);
908 }
909
910 unsigned long collationKey = djb2(collationString);
911
912 cache_entry = hash_search(collation_cache, &collationKey, HASH_ENTER, &found);
913 if (!found)
914 {
915 cache_entry->collationKey = collationKey;
916 UErrorCode status = U_ZERO_ERROR;
917 UCollator *collator = ucol_open(collationString, &status);
918
919 if (U_FAILURE(status))
920 {
921 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
922 errmsg(
923 "Collation is not supported by ICU for collation language tag: %s",
924 collationString),
925 errdetail_log(
926 "Collation is not supported by ICU for collation language tag: %s",
927 collationString)));
928 }
929
930 cache_entry->collator = collator;
931 }
932
933 return cache_entry;
934}
935
936
937/*

Callers 2

GetCollationSortKeyFunction · 0.85

Calls 1

djb2Function · 0.85

Tested by

no test coverage detected