From 7df346f50eea856a36e1d24e96868e12e9a2c75d Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Thu, 12 Nov 2009 19:41:02 +0000 Subject: [PATCH] fix stringshare of small strings. _eina_stringshare_small_bucket_find() was receiving the plength with size -1 since the first character is the same, but inside it was not doing the same, thus it was always failing the first test based on size. SVN revision: 43634 --- legacy/eina/src/lib/eina_stringshare.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/legacy/eina/src/lib/eina_stringshare.c b/legacy/eina/src/lib/eina_stringshare.c index e2b5a6ef0a..159ffbea0e 100644 --- a/legacy/eina/src/lib/eina_stringshare.c +++ b/legacy/eina/src/lib/eina_stringshare.c @@ -410,7 +410,15 @@ static Eina_Stringshare_Small _eina_small_share; static inline int _eina_stringshare_small_cmp(const Eina_Stringshare_Small_Bucket *bucket, int i, const char *pstr, unsigned char plength) { - const unsigned char cur_plength = bucket->lengths[i]; + /* pstr and plength are from second char and on, since the first is + * always the same. + * + * First string being always the same, size being between 2 and 3 + * characters (there is a check for special case length==1 and then + * small stringshare is applied to strings < 4), we just need to + * compare 2 characters of both strings. + */ + const unsigned char cur_plength = bucket->lengths[i] - 1; const char *cur_pstr; if (cur_plength > plength) @@ -440,7 +448,7 @@ static const char * _eina_stringshare_small_bucket_find(const Eina_Stringshare_Small_Bucket *bucket, const char *str, unsigned char length, int *index) { const char *pstr = str + 1; /* skip first letter, it's always the same */ - unsigned char plength = length; + unsigned char plength = length - 1; int i, low, high; if (bucket->count == 0)