added #fastFromString: (for Andis IEC-SocketInterface)
authorClaus Gittinger <cg@exept.de>
Fri, 10 Jul 1998 00:11:20 +0200
changeset 3639 c4fbb700a569
parent 3638 edf314b220d2
child 3640 523d80dfc3ac
added #fastFromString: (for Andis IEC-SocketInterface)
Integer.st
--- a/Integer.st	Thu Jul 09 10:25:57 1998 +0200
+++ b/Integer.st	Fri Jul 10 00:11:20 1998 +0200
@@ -87,6 +87,54 @@
     "Modified: 19.10.1997 / 18:09:04 / cg"
 !
 
+fastFromString:aString at:startIndex
+    "return the next unsigned Integer from the string 
+     as a decimal number, starting at startIndex. 
+     No spaces are skipped.
+
+     This is a specially tuned entry (using a low-level C-call), which
+     returns garbage if the argument string is not a small integer number.
+     It has been added to allow higher speed string decomposition into
+     numbers."
+%{
+     if (__isString(aString) && __isSmallInteger(startIndex)) {
+        char *cp = (char *)(__stringVal(aString));
+        int idx = __intVal(startIndex) - 1;
+        INT val;
+
+        if ((unsigned)idx < __stringSize(aString)) {
+            val = atoi(cp + idx);
+            RETURN (__MKINT(val));
+        }
+     }
+%}.
+     self primitiveFailed.
+
+    "
+     Integer fastFromString:'12345' at:1  
+     Integer fastFromString:'12345' at:2  
+     Integer fastFromString:'12345' at:3  
+     Integer fastFromString:'12345' at:4  
+     Integer fastFromString:'12345' at:5  
+     Integer fastFromString:'12345' at:6  
+     Integer fastFromString:'12345' at:0  
+
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            Integer readFrom:'12345'
+        ]
+     ]
+    "
+
+    "
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            Integer fastFromString:'12345' at:1  
+        ]
+     ]
+    "
+!
+
 new:numberOfBytes neg:negative
     "for ST-80 compatibility:
      Return an empty Integer (uninitialized value) with space for
@@ -1517,5 +1565,5 @@
 !Integer class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.82 1998-07-09 08:25:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.83 1998-07-09 22:11:20 cg Exp $'
 ! !