From db6d86a6c1b5bb15511e4e4015af889d4206be1d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 6 Oct 2012 18:12:19 -0400 Subject: [PATCH] Remove shared-str pool We used to have a shared-str pool. Removed to make thread-safety work easier. My measurements show that the extra overhead is not significant by any means. --- src/fcpat.c | 58 +++++++--------------------------------------------------- 1 file changed, 7 insertions(+), 51 deletions(-) diff --git a/src/fcpat.c b/src/fcpat.c index d93eb73..9d95266 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -1147,66 +1147,22 @@ bail0: return NULL; } -#define OBJECT_HASH_SIZE 251 -static struct objectBucket { - struct objectBucket *next; - FcChar32 hash; - int ref_count; -} *FcObjectBuckets[OBJECT_HASH_SIZE]; + +/* We used to have a shared-str pool. Removed to make thread-safety + * work easier. My measurements show that the extra overhead is not + * significant by any means. */ FcBool FcSharedStrFree (const FcChar8 *name) { - FcChar32 hash = FcStringHash (name); - struct objectBucket **p; - struct objectBucket *b; - int size; - - for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) - if (b->hash == hash && ((char *)name == (char *) (b + 1))) - { - b->ref_count--; - if (!b->ref_count) - { - *p = b->next; - size = sizeof (struct objectBucket) + strlen ((char *)name) + 1; - size = (size + 3) & ~3; - free (b); - } - return FcTrue; - } - return FcFalse; + free (name); + return FcTrue; } const FcChar8 * FcSharedStr (const FcChar8 *name) { - FcChar32 hash = FcStringHash (name); - struct objectBucket **p; - struct objectBucket *b; - int size; - - for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) - if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1))) - { - b->ref_count++; - return (FcChar8 *) (b + 1); - } - size = sizeof (struct objectBucket) + strlen ((char *)name) + 1; - /* - * workaround valgrind warning because glibc takes advantage of how it knows memory is - * allocated to implement strlen by reading in groups of 4 - */ - size = (size + 3) & ~3; - b = malloc (size); - if (!b) - return NULL; - b->next = 0; - b->hash = hash; - b->ref_count = 1; - strcpy ((char *) (b + 1), (char *)name); - *p = b; - return (FcChar8 *) (b + 1); + return strdup (name); } FcBool -- 2.7.4