class: CharacterWriteStream
added: #characterSizeChangedTo:size:
removed: #characterSizeChanged:size:
changed:
#next:put:
#nextPut:
#nextPutAll:
#nextPutAll:startingAt:to:
--- a/CharacterWriteStream.st Sat Jul 18 01:25:23 2015 +0200
+++ b/CharacterWriteStream.st Sat Jul 18 01:26:11 2015 +0200
@@ -99,22 +99,19 @@
!CharacterWriteStream methodsFor:'private'!
-characterSizeChanged:aCharacterOrString size:additionalSize
- "change aCollection to fit the size of aCharacter"
+characterSizeChangedTo:newCharacterSize size:additionalSize
+ "change aCollection to fit the size of newCharacterSize"
- |sz newSz bitsPerCharacter|
+ |sz newSz|
- bitsPerCharacter := aCharacterOrString bitsPerCharacterInString.
- currentCharacterSize < bitsPerCharacter ifTrue:[
- sz := collection size.
+ currentCharacterSize < newCharacterSize ifTrue:[
+ newSz := sz := collection size.
position + additionalSize >= sz ifTrue:[
- newSz := sz + additionalSize.
- ] ifFalse:[
- newSz := sz.
+ newSz := newSz + additionalSize + 100. "add some more space, maybe more will be added"
].
- collection := (aCharacterOrString stringSpecies new:newSz)
+ collection := ((CharacterArray speciesForCharacterSize:newCharacterSize) new:newSz)
replaceFrom:1 to:sz with:collection startingAt:1.
- currentCharacterSize := bitsPerCharacter.
+ currentCharacterSize := collection bitsPerCharacter.
].
! !
@@ -142,42 +139,36 @@
Redefined to avoid count grows of the underlying collection -
instead a single grow on the final size is performed."
- aCharacter bitsPerCharacterInString > currentCharacterSize ifTrue:[
- self characterSizeChanged:aCharacter size:count.
+ |needCharacterSize|
+
+ needCharacterSize := aCharacter characterSize.
+ needCharacterSize > currentCharacterSize ifTrue:[
+ self characterSizeChangedTo:needCharacterSize size:count.
].
super next:count put:aCharacter
!
nextPut:aCharacter
"append the argument, aCharacter to the stream.
- Specially tuned for appending to String, ByteArray and Array streams."
+ Specially tuned for appending to String, Unicode16String and Unicode32String streams."
%{ /* NOCONTEXT */
#ifndef NO_PRIM_STREAM
- REGISTER int pos;
- unsigned ch;
- 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) && __isCharacter(aCharacter)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1;
- wL = __INST(writeLimit);
+ REGISTER int pos = __intVal(p) + 1; /* make 1-based */
+ OBJ wL = __INST(writeLimit);
if ((wL == nil)
|| (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
- OBJ cls;
+ OBJ cls = __qClass(coll);
+ unsigned ch = __intVal(__characterVal(aCharacter));
+ OBJ rL = __INST(readLimit);
+ int __readLimit = -1;
- cls = __qClass(coll);
- ch = __intVal(__characterVal(aCharacter));
-
- rL = __INST(readLimit);
if (__isSmallInteger(rL)) {
__readLimit = __intVal(rL);
}
@@ -225,10 +216,14 @@
(writeLimit isNil
or:[(position + 1) <= writeLimit]) ifTrue:[
- currentCharacterSize < aCharacter bitsPerCharacterInString ifTrue:[
- self characterSizeChanged:aCharacter size:1.
+ |needCharacterSize|
+
+ needCharacterSize := aCharacter characterSize.
+ needCharacterSize > currentCharacterSize ifTrue:[
+ self characterSizeChangedTo:needCharacterSize size:1.
+ ] ifFalse:[
+ (position >= collection size) ifTrue:[self growCollection].
].
- (position >= collection size) ifTrue:[self growCollection].
collection at:(position + 1) put:aCharacter.
(position >= readLimit) ifTrue:[readLimit := (position + 1)].
position := position + 1.
@@ -242,15 +237,21 @@
"append aCollection to the receiver.
Redefined to convert to a string of the needed charcter size."
- aCollection bitsPerCharacterInString > currentCharacterSize ifTrue:[
- self characterSizeChanged:aCollection size:aCollection size.
+ |needCharacterSize|
+
+ needCharacterSize := aCollection characterSize.
+ needCharacterSize > currentCharacterSize ifTrue:[
+ self characterSizeChangedTo:needCharacterSize size:aCollection size.
].
super nextPutAll:aCollection
!
nextPutAll:aCollection startingAt:start to:stop
- aCollection bitsPerCharacterInString > currentCharacterSize ifTrue:[
- self characterSizeChanged:aCollection size:stop-start+1.
+ |needCharacterSize|
+
+ needCharacterSize := aCollection characterSize.
+ needCharacterSize > currentCharacterSize ifTrue:[
+ self characterSizeChangedTo:needCharacterSize size:stop-start+1.
].
^ super nextPutAll:aCollection startingAt:start to:stop
!