--- a/SmallInteger.st Sat Oct 27 08:50:24 2018 +0200
+++ b/SmallInteger.st Sat Oct 27 08:54:51 2018 +0200
@@ -94,6 +94,58 @@
- SmallIntegers cannot be created with new"
self error:'instances of SmallInteger cannot be created with new'
+!
+
+fastFromString:aString at:startIndex
+ "return the next SmallInteger from the string starting at startIndex.
+ No spaces are skipped.
+ Raises an error, if the index is out of bounds,
+ Returns garbage if the argument string is not a valid integer.
+
+ This is a specially tuned entry (using a low-level C-call to atol).
+ It has been added to allow high speed string decomposition into
+ numbers, especially for mass-data (reading millions of numbers)."
+
+%{ /* NOCONTEXT */
+ if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
+ char *cp = (char *)(__stringVal(aString));
+ int idx = __intVal(startIndex) - 1;
+ long atol(const char *);
+
+ if ((unsigned)idx < __stringSize(aString)) {
+ long val = atol(cp + idx);
+ RETURN (__MKINT(val));
+ }
+ }
+%}.
+ self primitiveFailed.
+
+ "
+ SmallInteger fastFromString:'hello12345' at:6
+ SmallInteger fastFromString:'12345' at:1
+ SmallInteger fastFromString:'12345' at:2
+ SmallInteger fastFromString:'12345' at:3
+ SmallInteger fastFromString:'12345' at:4
+ SmallInteger fastFromString:'12345' at:5
+ SmallInteger fastFromString:'12345' at:6
+ SmallInteger fastFromString:'12345' at:0
+
+ Time millisecondsToRun:[
+ 1000000 timesRepeat:[
+ SmallInteger readFrom:'12345'
+ ]
+ ]
+ "
+
+ "
+ Time millisecondsToRun:[
+ 1000000 timesRepeat:[
+ SmallInteger fastFromString:'12345' at:1
+ ]
+ ]
+ "
+
+ "Created: / 27-10-2018 / 08:52:32 / Claus Gittinger"
! !
!SmallInteger class methodsFor:'bit mask constants'!