--- a/WriteStream.st Fri May 13 20:17:32 2016 +0200
+++ b/WriteStream.st Sat May 14 09:34:43 2016 +0200
@@ -551,38 +551,26 @@
%{ /* NOCONTEXT */
#ifndef NO_PRIM_STREAM
- REGISTER int pos;
- OBJ coll;
- OBJ p, wL, rL;
- int __readLimit = -1;
-
- coll = __INST(collection);
- p = __INST(position);
+ OBJ coll = __INST(collection);
+ OBJ p = __INST(position);
if (__isNonNilObject(coll) && __isSmallInteger(p) && __isSmallInteger(anObject)) {
- unsigned ch;
-
- ch = __intVal(anObject);
+ OBJ wL = __INST(writeLimit);
+ INT pos = __intVal(p) + 1; /* make 1-based and usable for update below */
+ unsigned int ch = __intVal(anObject);
- pos = __intVal(p);
- /* make 1-based and usable for update below */
- pos = pos + 1;
- wL = __INST(writeLimit);
+ if (ch <= 0xFF && /* ch is unsigned */
+ ((wL == nil) || (__isSmallInteger(wL) && (pos <= __intVal(wL))))) {
+ OBJ cls = __qClass(coll);
+ OBJ rL = __INST(readLimit);
+ INT __readLimit = -1;
- if ((wL == nil)
- || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
- OBJ cls;
-
- cls = __qClass(coll);
-
- rL = __INST(readLimit);
if (__isSmallInteger(rL)) {
__readLimit = __intVal(rL);
}
if (cls == @global(String)) {
- if ((pos <= __stringSize(coll))
- && (ch <= 0xFF)) { /* ch is unsigned */
+ if (pos <= __stringSize(coll)) {
__StringInstPtr(coll)->s_element[pos-1] = ch;
advancePositionAndReturn: ;
if ((__readLimit >= 0) && (pos > __readLimit)) {
@@ -592,8 +580,7 @@
RETURN ( anObject );
}
} else if (cls == @global(ByteArray)) {
- if ((pos <= __byteArraySize(coll))
- && (ch <= 0xFF)) { /* ch is unsigned */
+ if (pos <= __byteArraySize(coll)) {
__ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
goto advancePositionAndReturn;
}
@@ -602,7 +589,13 @@
}
#endif
%}.
- ^ super nextPutByte:anObject
+ ((writeLimit isNil or:[(position + 1) <= writeLimit])
+ and:[position >= collection size]) ifTrue:[
+ self growCollection.
+ ^ self nextPutByte:anObject. "try again"
+ ] ifFalse:[
+ ^ super nextPutByte:anObject
+ ].
!
nextPutBytes:count from:anObject startingAt:start