Merge jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 11 Jul 2016 09:20:09 +0100
branchjv
changeset 20134 cab81d17f2d9
parent 20133 fefb47dc71f6 (current diff)
parent 20130 f5f12388c4fb (diff)
child 20136 8e3509beb85d
Merge
AbstractOperatingSystem.st
Integer.st
PeekableStream.st
ReadStream.st
--- a/AbstractOperatingSystem.st	Mon Jul 11 09:18:21 2016 +0100
+++ b/AbstractOperatingSystem.st	Mon Jul 11 09:20:09 2016 +0100
@@ -6017,7 +6017,7 @@
      that they can deal with timestamps after 2038 (especially: win32 will do so).
      Notice that timestamp is prepared to compensate for any OS limitation by computing the timeInfo
      components itself.
-     So it is usually (except for a little performance) no problem to return a reange too small here."
+     So it is usually (except for a little performance) no problem to return a range too small here."
 
     ^ (SmallInteger maxVal * 2 + 1) * 1000
 !
@@ -6139,7 +6139,7 @@
      timer wraps."
 
 %{  /* NOCONTEXT */
-    RETURN ( __mkSmallInteger(0x0FFFFFFF) );
+    RETURN ( __mkSmallInteger(_MAX_INT >> 2) );
 %}
 !
 
@@ -6174,31 +6174,27 @@
      This should really be moved to some RelativeTime class."
 
     (msTime1 > msTime2) ifTrue:[
-	((msTime1 - msTime2) < 16r10000000) ifTrue:[
-	    ^ true
-	].
+        ^ (msTime1 - msTime2) <= (SmallInteger maxVal // 4).
     ] ifFalse:[
-	((msTime2 - msTime1) > 16r10000000) ifTrue:[
-	    ^ true
-	].
+        ^ (msTime2 - msTime1) > ((SmallInteger maxVal // 4) + 1)
     ].
-    ^ false
 !
 
 millisecondTimeAdd:msTime1 and:msTime2
     "Add two millisecond times (such as returned getMillisecondTime).
-     The returned value is msTime1 + msTime2 where a wrap occurs at:16r1FFFFFFF.
+     The returned value is msTime1 + msTime2 where a wrap occurs 
+     at:16r1FFFFFFF (32-bit systems) or:16r1FFFFFFFFFFFFFFF (64-bit systems).
 
      This should really be moved to some RelativeTime class."
 
     |sum|
 
     sum := msTime1 + msTime2.
-    (sum > 16r1FFFFFFF) ifTrue:[
-	self assert:(sum <= 16r3FFFFFFF) message:'overflow in timer computation'.
-	^ sum - 16r20000000.
+    (sum > (SmallInteger maxVal // 2)) ifTrue:[
+        self assert:(sum <= SmallInteger maxVal) message:'overflow in timer computation'.
+        ^ sum - (SmallInteger maxVal // 2 + 1).
     ].
-    (sum < 0) ifTrue:[^ sum + 16r20000000].
+    (sum < 0) ifTrue:[^ sum + (SmallInteger maxVal // 2 + 1)].
     ^ sum
 !
 
@@ -6215,14 +6211,16 @@
     |diff|
 
     diff := msTime1 - msTime2.
-    diff > 16r-10000000 ifTrue:[
-	(diff < 16r10000000) ifTrue:[
-	    ^ diff.
-	] ifFalse:[
-	    ^ diff - 16r20000000.
-	].
+
+    diff < (SmallInteger maxVal // -4) ifTrue:[
+        ^ diff + (SmallInteger maxVal // 2) + 1.
     ].
-    ^ diff + 16r20000000
+
+    diff <= (SmallInteger maxVal // 4) ifTrue:[
+        ^ diff.
+    ] ifFalse:[
+        ^ diff - (SmallInteger maxVal // 2 + 1).
+    ].
 
 
     "
--- a/Integer.st	Mon Jul 11 09:18:21 2016 +0100
+++ b/Integer.st	Mon Jul 11 09:20:09 2016 +0100
@@ -331,7 +331,7 @@
      No whitespace-skipping is done.
      Returns the value of exceptionBlock, if no number is available."
 
-    |str nextChar nextChar2 nextChar3 nextChar4 value
+    |str nextChar value
      r     "{ Class: SmallInteger }"
      r2    "{ Class: SmallInteger }"
      r3    "{ Class: SmallInteger }"
@@ -341,14 +341,10 @@
     str := aStringOrStream readStream.
 
     nextChar := str peekOrNil.
-    (nextChar notNil and:[nextChar isDigitRadix:radix]) ifFalse:[
+    (nextChar isNil or:[(value := nextChar digitValueRadix:radix) isNil]) ifTrue:[
         ^ exceptionBlock value
     ].
 
-    value := nextChar digitValue.
-    str next.
-    nextChar := str peekOrNil.
-
 "/ OLD code
 "/    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
 "/        str next.
@@ -364,33 +360,31 @@
 
     r := radix.
     r2 := r * r.
-    r3 := r2 * r.
     r4 := r2 * r2.
 
-    [nextChar notNil and:[ (digit1 := nextChar digitValueRadix:r) notNil]] whileTrue:[
+    [
+        nextChar := str nextPeekOrNil.
+        nextChar notNil and:[(digit1 := nextChar digitValueRadix:r) notNil]
+    ] whileTrue:[
         "/ read 4 chars and pre-compute their value to avoid largeInt operations.
 
-        str next.
-        nextChar2 := str peekOrNil.
-        (nextChar2 isNil or:[ (digit2 := nextChar2 digitValueRadix:r) isNil]) ifTrue:[
+        nextChar := str nextPeekOrNil.
+        (nextChar isNil or:[(digit2 := nextChar digitValueRadix:r) isNil]) ifTrue:[
             ^ (value * r) + digit1.
         ].
 
-        str next.
-        nextChar3 := str peekOrNil.
-        (nextChar3 isNil or:[ (digit3 := nextChar3 digitValueRadix:r) isNil]) ifTrue:[
-            ^ (value * r2) + ((digit1*r) + digit2).
+        nextChar := str nextPeekOrNil.
+        (nextChar isNil or:[(digit3 := nextChar digitValueRadix:r) isNil]) ifTrue:[
+            ^ (value * r2) + ((digit1*r) + digit2) .
         ].
 
-        str next.
-        nextChar4 := str peekOrNil.
-        (nextChar4 isNil or:[ (digit4 := nextChar4 digitValueRadix:r) isNil]) ifTrue:[
+        nextChar := str nextPeekOrNil.
+        (nextChar isNil or:[ (digit4 := nextChar digitValueRadix:r) isNil]) ifTrue:[
+            r3 := r2 * r.
             ^ (value * r3) + ((((digit1*r) + digit2)*r) + digit3).
         ].
 
         value := (value * r4) + ((((((digit1*r) + digit2)*r) + digit3)*r) + digit4).
-        str next.
-        nextChar := str peekOrNil.
     ].
     ^ value
 
@@ -401,10 +395,13 @@
      Integer readFrom:(ReadStream on:'foobar') radix:10
      Integer readFrom:(ReadStream on:'foobar') radix:10 onError:nil
      Integer readFrom:'gg' radix:10 onError:0
-
+     Integer readFrom:'' radix:10 onError:'wrong'
+
+     |s|
+     s := String new:1000 withAll:$1.
      Time millisecondsToRun:[
         1000 timesRepeat:[
-            (String new:1000 withAll:$1) asInteger
+            s asInteger
         ]
      ]
     "
--- a/PeekableStream.st	Mon Jul 11 09:18:21 2016 +0100
+++ b/PeekableStream.st	Mon Jul 11 09:20:09 2016 +0100
@@ -595,6 +595,13 @@
     ^ self peek
 !
 
+nextPeekOrNil
+    "advance to next element and return the peeked element"
+
+    self nextOrNil.
+    ^ self peekOrNil
+!
+
 nextUpTo:anObject
     "read a collection of all objects up-to anObject and return these
      elements, but excluding anObject. 
--- a/ReadStream.st	Mon Jul 11 09:18:21 2016 +0100
+++ b/ReadStream.st	Mon Jul 11 09:20:09 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -99,6 +97,7 @@
     "Modified: / 12-09-2010 / 13:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+
 !ReadStream methodsFor:'converting'!
 
 readStream
@@ -561,23 +560,18 @@
      - tuned for speed on String-Streams for faster scanning"
 
 %{  /* NOCONTEXT */
-    OBJ coll, l, p;
-
-    coll = __INST(collection);
-    p = __INST(position);
-    l = __INST(readLimit);
+    OBJ coll = __INST(collection);
+    OBJ p = __INST(position);
+    OBJ l = __INST(readLimit);
 
     if (__isStringLike(coll) && __bothSmallInteger(p, l)) {
-	REGISTER INT pos;
-	unsigned ch;
+        REGISTER INT pos  = __intVal(p) + 1;
 
-	pos = __intVal(p);
-	pos++;
-	if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) {
-	    ch = __stringVal(coll)[pos];
-	    __INST(position) = __mkSmallInteger(pos);
-	    RETURN ( __MKCHARACTER(ch) );
-	}
+        if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) {
+            unsigned int ch = __stringVal(coll)[pos];
+            __INST(position) = __mkSmallInteger(pos);
+            RETURN ( __MKCHARACTER(ch) );
+        }
     }
 %}.
     (position >= readLimit) ifTrue:[^ self pastEndRead].
@@ -586,6 +580,32 @@
     ^ collection at:(position + 1)
 !
 
+nextPeekOrNil
+    "advance read pointer return the peek element.
+     this is equivalent to (self next; peekOrNil).
+     - tuned for speed on String-Streams for faster scanning"
+
+%{  /* NOCONTEXT */
+    OBJ coll = __INST(collection);
+    OBJ p = __INST(position);
+    OBJ l = __INST(readLimit);
+
+    if (__isStringLike(coll) && __bothSmallInteger(p, l)) {
+        REGISTER INT pos  = __intVal(p) + 1;
+
+        if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) {
+            unsigned int ch = __stringVal(coll)[pos];
+            __INST(position) = __mkSmallInteger(pos);
+            RETURN ( __MKCHARACTER(ch) );
+        }
+    }
+%}.
+    (position >= readLimit) ifTrue:[^ nil].
+    position := position + 1.
+    (position >= readLimit) ifTrue:[^ nil].
+    ^ collection at:(position + 1)
+!
+
 nextUnicode16CharacterMSB:msb
     ^ Character value:(self nextUnsignedInt16MSB:msb)