added #fastFromString:
authorClaus Gittinger <cg@exept.de>
Fri, 18 Jun 1999 14:40:14 +0200
changeset 4297 302e80e0b14a
parent 4296 2c967ce1879d
child 4298 1889f8051f69
added #fastFromString:
SFloat.st
ShortFloat.st
--- a/SFloat.st	Fri Jun 18 14:38:49 1999 +0200
+++ b/SFloat.st	Fri Jun 18 14:40:14 1999 +0200
@@ -145,6 +145,62 @@
 %}
 !
 
+fastFromString:aString at:startIndex
+    "return the next ShortFloat from the string 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 valid float 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;
+        double atof();
+        double val;
+
+        if ((unsigned)idx < __stringSize(aString)) {
+            val = atof(cp + idx);
+            RETURN (__MKSFLOAT(val));
+        }
+     }
+%}.
+     self primitiveFailed.
+
+    "
+     ShortFloat fastFromString:'123.45' at:1  
+     ShortFloat fastFromString:'123.45' at:2  
+     ShortFloat fastFromString:'123.45E4' at:1  
+     ShortFloat fastFromString:'hello123.45E4' at:6  
+     ShortFloat fastFromString:'12345' at:1  
+     ShortFloat fastFromString:'12345' at:2  
+     ShortFloat fastFromString:'12345' at:3  
+     ShortFloat fastFromString:'12345' at:4  
+     ShortFloat fastFromString:'12345' at:5  
+     ShortFloat fastFromString:'12345' at:6  
+     ShortFloat fastFromString:'12345' at:0  
+     ShortFloat fastFromString:'hello123.45E4' at:1  
+
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            ShortFloat readFrom:'123.45'
+        ]
+     ]
+    "
+
+    "
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            ShortFloat fastFromString:'123.45' at:1  
+        ]
+     ]
+    "
+
+
+
+!
+
 readFrom:aStringOrStream onError:exceptionBlock
     "read a shortFloat from a string"
 
@@ -904,5 +960,5 @@
 !ShortFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SFloat.st,v 1.45 1999-05-10 13:13:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SFloat.st,v 1.46 1999-06-18 12:40:14 cg Exp $'
 ! !
--- a/ShortFloat.st	Fri Jun 18 14:38:49 1999 +0200
+++ b/ShortFloat.st	Fri Jun 18 14:40:14 1999 +0200
@@ -145,6 +145,62 @@
 %}
 !
 
+fastFromString:aString at:startIndex
+    "return the next ShortFloat from the string 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 valid float 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;
+        double atof();
+        double val;
+
+        if ((unsigned)idx < __stringSize(aString)) {
+            val = atof(cp + idx);
+            RETURN (__MKSFLOAT(val));
+        }
+     }
+%}.
+     self primitiveFailed.
+
+    "
+     ShortFloat fastFromString:'123.45' at:1  
+     ShortFloat fastFromString:'123.45' at:2  
+     ShortFloat fastFromString:'123.45E4' at:1  
+     ShortFloat fastFromString:'hello123.45E4' at:6  
+     ShortFloat fastFromString:'12345' at:1  
+     ShortFloat fastFromString:'12345' at:2  
+     ShortFloat fastFromString:'12345' at:3  
+     ShortFloat fastFromString:'12345' at:4  
+     ShortFloat fastFromString:'12345' at:5  
+     ShortFloat fastFromString:'12345' at:6  
+     ShortFloat fastFromString:'12345' at:0  
+     ShortFloat fastFromString:'hello123.45E4' at:1  
+
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            ShortFloat readFrom:'123.45'
+        ]
+     ]
+    "
+
+    "
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            ShortFloat fastFromString:'123.45' at:1  
+        ]
+     ]
+    "
+
+
+
+!
+
 readFrom:aStringOrStream onError:exceptionBlock
     "read a shortFloat from a string"
 
@@ -904,5 +960,5 @@
 !ShortFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.45 1999-05-10 13:13:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.46 1999-06-18 12:40:14 cg Exp $'
 ! !