fix stringshare of small strings.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 12 Nov 2009 19:41:02 +0000 (19:41 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 12 Nov 2009 19:41:02 +0000 (19:41 +0000)
_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.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@43634 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eina_stringshare.c

index e2b5a6e..159ffbe 100644 (file)
@@ -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)