class: WriteStream
changed:
#last:
#next:put:
#nextPutAll:
#nextPutAll:startingAt:to:
eliminated some leftover position1Based code.
--- a/WriteStream.st Wed Dec 03 22:02:02 2014 +0100
+++ b/WriteStream.st Thu Dec 04 17:36:06 2014 +0100
@@ -160,10 +160,7 @@
"return the last n elements as species of the underlying collection;
Report an error if the stream is empty"
- |position1Based|
-
- position1Based := position + 1.
- ^ collection copyFrom:(position1Based - n) to:(position1Based - 1).
+ ^ collection copyFrom:(position - n + 1) to:position.
"
|s|
@@ -304,7 +301,7 @@
Redefined to avoid count grows of the underlying collection -
instead a single grow on the final size is performed."
- |final position1Based|
+ |final|
count == 0 ifTrue:[^ self].
@@ -313,19 +310,14 @@
^ self.
].
- position1Based := position + 1.
- final := position1Based + count - 1.
+ final := position + count.
(final > collection size) ifTrue:[
self growCollection:final
].
- collection from:position1Based to:final put:anObject.
-"/ position1Based to:final do:[:index |
-"/ collection at:index put:anObject.
-"/ ].
- position1Based := position1Based + count.
- (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
- position := position1Based - 1.
+ collection from:position + 1 to:final put:anObject.
+ position := position + count.
+ (position >= readLimit) ifTrue:[readLimit := position].
"/ ^ anObject -- return self
"
@@ -443,19 +435,14 @@
Redefined to avoid count grows of the underlying collection -
instead a single grow on the final size is performed."
- |nMore final position1Based|
+ |nMore "{ Class: SmallInteger }"
+ final "{ Class: SmallInteger }" |
- collection isNil ifTrue:[
- super nextPutAll:aCollection.
- ^ self
- ].
aCollection isSequenceable ifFalse:[
super nextPutAll:aCollection.
^ self.
].
- position1Based := position + 1.
-
nMore := aCollection size.
nMore == 0 ifTrue:[
"/ for the programmer..
@@ -464,24 +451,23 @@
].
].
- final := position1Based + nMore - 1.
+ final := position + nMore.
(writeLimit notNil
and:[final > writeLimit]) ifTrue:[
final := writeLimit.
- nMore := final - position1Based + 1
+ nMore := final - position
].
(final > collection size) ifTrue:[
self growCollection:final
].
collection
- replaceFrom:position1Based
+ replaceFrom:(position + 1)
to:final
with:aCollection
startingAt:1.
- position1Based := position1Based + nMore.
- (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
- position := position1Based - 1.
+ (position >= readLimit) ifTrue:[readLimit := position].
+ position := position + nMore.
"/ ^ aCollection -- self
"Modified: / 04-09-2011 / 20:03:32 / cg"
@@ -509,32 +495,30 @@
Redefined to avoid count grows of the underlying collection -
instead a single grow on the final size is performed."
- |nMore final position1Based|
+ |nMore final|
collection isNil ifTrue:[
^ super nextPutAll:aCollection startingAt:pos1 to:pos2
].
- position1Based := position + 1.
nMore := pos2 - pos1 + 1.
- final := position1Based + nMore - 1.
+ final := position + nMore.
(writeLimit notNil
and:[final > writeLimit]) ifTrue:[
final := writeLimit.
- nMore := final - position1Based + 1
+ nMore := final - position
].
(final > collection size) ifTrue:[
self growCollection:final
].
- collection replaceFrom:position1Based
+ collection replaceFrom:position + 1
to:final
with:aCollection
startingAt:pos1.
- position1Based := position1Based + nMore.
- (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
- position := position1Based - 1.
+ position := position + nMore.
+ (position >= readLimit) ifTrue:[readLimit := position].
"/ ^ aCollection -- return self
"
@@ -667,10 +651,10 @@
!WriteStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.85 2014-11-15 16:08:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.86 2014-12-04 16:36:06 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.85 2014-11-15 16:08:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.86 2014-12-04 16:36:06 cg Exp $'
! !