Float.st
changeset 4295 4adf74ef8e3e
parent 3955 ebf11ebe113e
child 4296 2c967ce1879d
--- a/Float.st	Fri Jun 18 11:02:39 1999 +0200
+++ b/Float.st	Fri Jun 18 14:38:04 1999 +0200
@@ -227,6 +227,56 @@
 %}
 !
 
+fastFromString:aString at:startIndex
+    "return the next Float 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 (__MKFLOAT(val));
+        }
+     }
+%}.
+     self primitiveFailed.
+
+    "
+     Float fastFromString:'12345' at:1  
+     Float fastFromString:'12345' at:2  
+     Float fastFromString:'12345' at:3  
+     Float fastFromString:'12345' at:4  
+     Float fastFromString:'12345' at:5  
+     Float fastFromString:'12345' at:6  
+     Float fastFromString:'12345' at:0  
+
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            Float readFrom:'123.45'
+        ]
+     ]
+    "
+
+    "
+     Time millisecondsToRun:[
+        100000 timesRepeat:[
+            Float fastFromString:'123.45' at:1  
+        ]
+     ]
+    "
+
+
+!
+
 fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4
     "creates a double, given the four vax float bytes to an ieee double. 
      For NaNs and Infinity, nil is returned.
@@ -1853,6 +1903,6 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.91 1999-01-15 20:22:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.92 1999-06-18 12:38:04 cg Exp $'
 ! !
 Float initialize!