WriteStream.st
changeset 252 cf6eef7703ad
parent 95 d22739a0c6e9
child 260 cefb485445a7
--- a/WriteStream.st	Wed Feb 15 11:24:35 1995 +0100
+++ b/WriteStream.st	Wed Feb 15 11:25:20 1995 +0100
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -19,9 +19,9 @@
 
 WriteStream comment:'
 COPYRIGHT (c) 1989 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.10 1994-08-05 01:03:08 claus Exp $
+$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.11 1995-02-15 10:25:17 claus Exp $
 '!
 
 !WriteStream class methodsFor:'documentation'!
@@ -29,7 +29,7 @@
 copyright
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.10 1994-08-05 01:03:08 claus Exp $
+$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.11 1995-02-15 10:25:17 claus Exp $
 "
 !
 
@@ -83,11 +83,11 @@
     "return the current contents (a collection) of the stream"
 
     collection size == (position - 1) ifFalse:[
-        collection isFixedSize ifTrue:[
-            collection := collection copyFrom:1 to:(position - 1)
-        ] ifFalse:[
-            collection grow:(position - 1)
-        ]
+	collection isFixedSize ifTrue:[
+	    collection := collection copyFrom:1 to:(position - 1)
+	] ifFalse:[
+	    collection grow:(position - 1)
+	]
     ].
     ^ collection
 !
@@ -125,62 +125,63 @@
     REGISTER int pos;
     unsigned ch;
     OBJ coll;
-    OBJ t;
+    OBJ p, l;
 
     coll = _INST(collection);
-    if (_isNonNilObject(coll)
-     && _isSmallInteger(t = _INST(position))) {
+    p = _INST(position);
+    l = _INST(writeLimit);
 
-        pos = _intVal(t);
+    if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
 
-        if (_isSmallInteger(t = _INST(writeLimit)) 
-         && (pos <= _intVal(t)) && (pos > 0)) {
-            OBJ cls;
+	pos = _intVal(p);
 
-            cls = _qClass(coll);
+	if ((pos <= _intVal(l)) && (pos > 0)) {
+	    OBJ cls;
+
+	    cls = _qClass(coll);
 #ifdef NOTDEF
-            if (cls == String) {
-                if (__isCharacter(anObject) 
-                 && (pos <= _stringSize(coll))) {
-                    _StringInstPtr(coll)->s_element[pos-1] = _intVal(_characterVal(anObject));
-                    _INST(position) = _MKSMALLINT(pos + 1);
-                    if (_isSmallInteger(_INST(readLimit))
-                     && (pos >= _intVal(_INST(readLimit)))) {
-                        _INST(readLimit) = _MKSMALLINT(pos + 1);
-                    }
-                    RETURN ( anObject );
-                }
-            } else 
+	    if (cls == String) {
+		if (__isCharacter(anObject) 
+		 && (pos <= _stringSize(coll))) {
+		    _StringInstPtr(coll)->s_element[pos-1] = _intVal(_characterVal(anObject));
+		    _INST(position) = _MKSMALLINT(pos + 1);
+		    if (__isSmallInteger(_INST(readLimit))
+		     && (pos >= _intVal(_INST(readLimit)))) {
+			_INST(readLimit) = _MKSMALLINT(pos + 1);
+		    }
+		    RETURN ( anObject );
+		}
+	    } else 
 #endif
-            if (cls == ByteArray) {
-                if (_isSmallInteger(anObject) 
-                 && ((ch = _intVal(anObject)) >= 0)
-                 && (ch <= 255)
-                 && (pos <= _byteArraySize(coll))) {
-                    _ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
-                    _INST(position) = _MKSMALLINT(pos + 1);
-                    if (_isSmallInteger(_INST(readLimit))
-                     && (pos >= _intVal(_INST(readLimit)))) {
-                        _INST(readLimit) = _MKSMALLINT(pos + 1);
-                    }
-                    RETURN ( anObject );
-                }
+	    if (cls == ByteArray) {
+		if (__isSmallInteger(anObject) 
+		 && ((ch = _intVal(anObject)) >= 0)
+		 && (ch <= 255)
+		 && (pos <= _byteArraySize(coll))) {
+		    _ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
+		    _INST(position) = _MKSMALLINT(pos + 1);
+		    if (__isSmallInteger(_INST(readLimit))
+		     && (pos >= _intVal(_INST(readLimit)))) {
+			_INST(readLimit) = _MKSMALLINT(pos + 1);
+		    }
+		    RETURN ( anObject );
+		}
 #ifdef NOTDEF
-            } else 
-            if (cls == Array) {
-                if (pos <= _arraySize(coll)) {
-                     _ArrayInstPtr(coll)->a_element[pos-1] = anObject;
-                    __STORE(coll, anObject);
-                    _INST(position) = _MKSMALLINT(pos + 1);
-                    if (_isSmallInteger(_INST(readLimit))
-                     && (pos >= _intVal(_INST(readLimit)))) {
-                        _INST(readLimit) = _MKSMALLINT(pos + 1);
-                    }
-                    RETURN ( anObject );
-                }
+	    } else 
+	    if (cls == Array) {
+		if (pos <= _arraySize(coll)) {
+		     _ArrayInstPtr(coll)->a_element[pos-1] = anObject;
+		    __STORE(coll, anObject);
+		    _INST(position) = _MKSMALLINT(pos + 1);
+		    if (__isSmallInteger(_INST(readLimit))
+		     && (pos >= _intVal(_INST(readLimit)))) {
+			_INST(readLimit) = _MKSMALLINT(pos + 1);
+		    }
+		    RETURN ( anObject );
+		}
 #endif
-            }
-        }
+	    }
+	}
     }
 #endif
 
@@ -201,15 +202,15 @@
     |final|
 
     collection isNil ifTrue:[
-        count timesRepeat:[
-            self nextPut:anObject
-        ].
-        ^ self
+	count timesRepeat:[
+	    self nextPut:anObject
+	].
+	^ self
     ].
 
     final := position + count - 1.
     (final > collection size) ifTrue:[
-        self growCollection:final
+	self growCollection:final
     ].
     collection atAll:(position to:final) put:anObject.
 
@@ -226,21 +227,21 @@
     |nMore final|
 
     collection isNil ifTrue:[
-        aCollection do:[:element |
-            self nextPut:element
-        ].
-        ^ self
+	aCollection do:[:element |
+	    self nextPut:element
+	].
+	^ self
     ].
 
     nMore := aCollection size.
     final := position + nMore - 1.
     (final > collection size) ifTrue:[
-        self growCollection:final
+	self growCollection:final
     ].
     collection replaceFrom:position
-                        to:final
-                      with:aCollection 
-                startingAt:1.
+			to:final
+		      with:aCollection 
+		startingAt:1.
 
     position := position + nMore.
     (position > readLimit) ifTrue:[readLimit := position - 1].
@@ -272,42 +273,46 @@
 !WriteStream methodsFor:'private'!
 
 growCollection
+    self growCollection:10
+
+"/    |oldSize newSize newColl|
+
+"/    oldSize := collection size.
+"/    (oldSize == 0) ifTrue:[
+"/        newSize := 10
+"/  ] ifFalse:[
+"/      newSize := oldSize * 2
+"/  ].
+"/  collection isFixedSize ifTrue:[
+"/      newColl := collection species new:newSize.
+"/      newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
+"/      collection := newColl
+"/  ] ifFalse:[
+"/      collection grow:newSize.
+"/  ].
+"/  writeLimit := newSize
+!
+
+growCollection:minNewSize
+    "grow the streamed collection to at least minNewSize"
+
     |oldSize newSize newColl|
 
     oldSize := collection size.
     (oldSize == 0) ifTrue:[
-        newSize := 10
+	newSize := minNewSize
     ] ifFalse:[
-        newSize := oldSize * 2
+	newSize := oldSize * 2.
+	[newSize < minNewSize] whileTrue:[
+	    newSize := newSize * 2
+	]
     ].
     collection isFixedSize ifTrue:[
-        newColl := collection species new:newSize.
-        newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
-        collection := newColl
+	newColl := collection species new:newSize.
+	newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
+	collection := newColl
     ] ifFalse:[
-        collection grow:newSize.
-    ].
-    writeLimit := newSize
-!
-
-growCollection:minNewSize
-    |oldSize newSize newColl|
-
-    oldSize := collection size.
-    (oldSize == 0) ifTrue:[
-        newSize := minNewSize
-    ] ifFalse:[
-        newSize := oldSize * 2.
-        [newSize < minNewSize] whileTrue:[
-            newSize := newSize * 2
-        ]
-    ].
-    collection isFixedSize ifTrue:[
-        newColl := collection species new:newSize.
-        newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
-        collection := newColl
-    ] ifFalse:[
-        collection grow:newSize
+	collection grow:newSize
     ].
     writeLimit := newSize
 ! !