Author: rfm
Date: Mon May 25 16:51:02 2015
New Revision: 38541

URL: http://svn.gna.org/viewcvs/gnustep?rev=38541&view=rev
Log:
some optionisation of string equality test ... don't compute hash of string
unless the string is large enough to make it worthwhile.

Modified:
    libs/base/trunk/Source/GSString.m

Modified: libs/base/trunk/Source/GSString.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSString.m?rev=38541&r1=38540&r2=38541&view=diff
==============================================================================
--- libs/base/trunk/Source/GSString.m   (original)
+++ libs/base/trunk/Source/GSString.m   Mon May 25 16:51:02 2015
@@ -2992,11 +2992,11 @@
     {
       return NO;
     }
-  if (GSObjCIsInstance(anObject) == NO)
+  c = object_getClass(anObject);
+  if (class_isMetaClass(c) == YES)
     {
       return NO;
     }
-  c = object_getClass(anObject);
   if (c == NSConstantStringClass)
     {
       return literalIsEqualInternal((NXConstantString*)anObject, (GSStr)self);
@@ -3006,15 +3006,24 @@
       GSStr    other = (GSStr)anObject;
       NSRange  r = {0, self->_count};
 
-      /*
-       * First see if the hash is the same - if not, we can't be equal.
+      /* First see if the hash is the same - if not, we can't be equal.
+       * However, it's not worth calculating hashes unless the strings
+       * are fairly long.
        */
-      if (self->_flags.hash == 0)
-        self->_flags.hash = (*hashImp)((id)self, hashSel);
-      if (other->_flags.hash == 0)
-        other->_flags.hash = (*hashImp)((id)other, hashSel);
-      if (self->_flags.hash != other->_flags.hash)
-       return NO;
+      if (self->_count > 15)
+        {
+          if (self->_flags.hash == 0)
+            self->_flags.hash = (*hashImp)((id)self, hashSel);
+          if (other->_flags.hash == 0)
+            other->_flags.hash = (*hashImp)((id)other, hashSel);
+          if (self->_flags.hash != other->_flags.hash)
+            return NO;
+        }
+      else if (self->_flags.hash && other->_flags.hash)
+        {
+          if (self->_flags.hash != other->_flags.hash)
+            return NO;
+        }
 
       /*
        * Do a compare depending on the type of the other string.
@@ -3055,11 +3064,11 @@
     {
       return NO;
     }
-  if (GSObjCIsInstance(anObject) == NO)
+  c = object_getClass(anObject);
+  if (class_isMetaClass(c) == YES)
     {
       return NO;
     }
-  c = object_getClass(anObject);
   if (c == NSConstantStringClass)
     {
       return literalIsEqualInternal((NXConstantString*)anObject, (GSStr)self);
@@ -3069,15 +3078,24 @@
       GSStr    other = (GSStr)anObject;
       NSRange  r = {0, self->_count};
 
-      /*
-       * First see if the hash is the same - if not, we can't be equal.
+      /* First see if the hash is the same - if not, we can't be equal.
+       * However, it's not worth calculating hashes unless the strings
+       * are fairly long.
        */
-      if (self->_flags.hash == 0)
-        self->_flags.hash = (*hashImp)((id)self, hashSel);
-      if (other->_flags.hash == 0)
-        other->_flags.hash = (*hashImp)((id)other, hashSel);
-      if (self->_flags.hash != other->_flags.hash)
-       return NO;
+      if (self->_count > 15)
+        {
+          if (self->_flags.hash == 0)
+            self->_flags.hash = (*hashImp)((id)self, hashSel);
+          if (other->_flags.hash == 0)
+            other->_flags.hash = (*hashImp)((id)other, hashSel);
+          if (self->_flags.hash != other->_flags.hash)
+            return NO;
+        }
+      else if (self->_flags.hash && other->_flags.hash)
+        {
+          if (self->_flags.hash != other->_flags.hash)
+            return NO;
+        }
 
       /*
        * Do a compare depending on the type of the other string.


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to