--- a/ReadStream.st Mon Sep 27 12:32:33 1999 +0200
+++ b/ReadStream.st Fri Oct 01 10:37:37 1999 +0200
@@ -43,6 +43,7 @@
"
! !
+
!ReadStream methodsFor:'converting'!
readStream
@@ -221,21 +222,55 @@
!
nextByte
- "return the next element as a byteValued integer"
+ "return the next element; advance read pointer.
+ return nil, if there is no next element.
+ - tuned for a bit more speed on String/ByteArray/Array-Streams"
|ret|
- ret := self next.
- ret notNil ifTrue:[
- ((ret < 0) or:[ret > 255]) ifTrue:[
- self error:'oops - not a byte value in stream' mayProceed:true.
- ^ nil
- ]
- ].
+%{ /* NOCONTEXT */
+
+ REGISTER int pos;
+ unsigned ch;
+ OBJ coll, p, l;
+
+ coll = __INST(collection);
+ p = __INST(position);
+ l = __INST(readLimit);
+
+ if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
+
+ pos = __intVal(p);
+ if (pos > 0 && pos <= __intVal(l)) {
+ OBJ cls;
+
+ cls = __qClass(coll);
+ if (cls == @global(String)) {
+ if (pos <= __stringSize(coll)) {
+ __INST(position) = __MKSMALLINT(pos + 1);
+ ch = __stringVal(coll)[pos-1];
+ RETURN ( __MKSMALLINT(ch) );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (pos <= __byteArraySize(coll)) {
+ __INST(position) = __MKSMALLINT(pos + 1);
+ ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
+ RETURN ( __MKSMALLINT(ch) );
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ __INST(position) = __MKSMALLINT(pos + 1);
+ RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
+ }
+ }
+ }
+ }
+%}
+.
+ (position > readLimit) ifTrue:[^ self pastEnd].
+ ret := collection at:position.
+ position := position + 1.
^ ret
-
- "Created: 13.9.1996 / 18:10:38 / cg"
- "Modified: 5.3.1997 / 21:16:12 / cg"
!
nextDecimalInteger
@@ -641,5 +676,5 @@
!ReadStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.39 1999-08-04 14:10:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.40 1999-10-01 08:37:37 cg Exp $'
! !