#TUNING by cg
authorClaus Gittinger <cg@exept.de>
Wed, 14 Sep 2016 08:54:18 +0200
changeset 20384 78b74ac7c891
parent 20383 f20466f6b0a4
child 20385 f8655a0e0503
#TUNING by cg class: String added: #includes:
String.st
--- a/String.st	Tue Sep 13 14:46:09 2016 +0200
+++ b/String.st	Wed Sep 14 08:54:18 2016 +0200
@@ -524,8 +524,6 @@
 ! !
 
 
-
-
 !String class methodsFor:'queries'!
 
 defaultPlatformClass
@@ -546,10 +544,6 @@
 ! !
 
 
-
-
-
-
 !String methodsFor:'accessing'!
 
 at:index
@@ -793,6 +787,55 @@
     "Created: / 10-01-2012 / 17:10:54 / cg"
 !
 
+includes:aCharacter
+    "return true, if the receiver includes aCharacter.
+     - redefined here for speed"
+
+%{  /* NOCONTEXT */
+#ifdef FAST_MEMCHR
+    REGISTER unsigned char *cp;
+    REGISTER unsigned byteValue;
+    int last;
+    OBJ cls;
+
+    if (__isCharacter(aCharacter)) {
+        byteValue = __intVal(__characterVal(aCharacter));
+        if (byteValue <= 0xFF) {            
+            last = __stringSize(self);
+            cp = __stringVal(self);
+            if ((cls = __qClass(self)) != String) {
+                int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+                cp += numInstBytes;
+                last -= numInstBytes;
+            }
+            cp = (unsigned char *) memchr(cp, byteValue, last);
+            RETURN ( (cp == NULL) ? false : true );
+        }
+        RETURN (false);
+    }
+#endif
+%}.
+    ^ (self indexOf:aCharacter startingAt:1) ~~ 0
+
+    "
+     'hello world' includes:$l
+     'hello world' includes:$W
+
+     |s|
+     s := String new:1024.
+     s atAllPut:$a.
+     s at:512 put:(Character space).
+     Time millisecondsToRun:[
+        1000000 timesRepeat:[ s includes:(Character space) ]
+     ]
+
+     timing (ms):
+            bcc                 OSX(2007 powerbook)
+                                 110    
+    "
+!
+
 includesAny:aCollection
     "return true, if the receiver includes any of the characters in the
      argument, aCollection.
@@ -4152,7 +4195,6 @@
     ^ super reverse
 ! !
 
-
 !String methodsFor:'substring searching'!
 
 indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
@@ -4829,7 +4871,6 @@
 
 ! !
 
-
 !String class methodsFor:'documentation'!
 
 version