WriteStream.st
branchjv
changeset 17732 a1892eeca6c0
parent 17728 bbc5fa73dfab
child 17734 406b1590afe8
equal deleted inserted replaced
17731:295728e8f410 17732:a1892eeca6c0
   306      instead a single grow on the final size is performed."
   306      instead a single grow on the final size is performed."
   307 
   307 
   308     |final position1Based|
   308     |final position1Based|
   309 
   309 
   310     (collection isNil or:[writeLimit notNil]) ifTrue:[
   310     (collection isNil or:[writeLimit notNil]) ifTrue:[
   311         ^ super next:count put:anObject
   311         super next:count put:anObject.
       
   312         ^ self.
   312     ].
   313     ].
   313 
   314 
   314     position1Based := position - ZeroPosition + 1.
   315     position1Based := position - ZeroPosition + 1.
   315     final := position1Based + count - 1.
   316     final := position1Based + count - 1.
   316     (final > collection size) ifTrue:[
   317     (final > collection size) ifTrue:[
   321         collection at:index put:anObject.
   322         collection at:index put:anObject.
   322     ].
   323     ].
   323     position1Based := position1Based + count.
   324     position1Based := position1Based + count.
   324     (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
   325     (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
   325     position := position1Based - 1 + ZeroPosition.
   326     position := position1Based - 1 + ZeroPosition.
   326     ^ anObject
   327     "/ ^ anObject -- return self
   327 !
   328 !
   328 
   329 
   329 next:n putAll:aCollection startingAt:pos1
   330 next:n putAll:aCollection startingAt:pos1
   330     "append some elements of the argument, aCollection to the stream."
   331     "append some elements of the argument, aCollection to the stream."
   331 
   332 
   437      instead a single grow on the final size is performed."
   438      instead a single grow on the final size is performed."
   438 
   439 
   439     |nMore final position1Based|
   440     |nMore final position1Based|
   440 
   441 
   441     collection isNil ifTrue:[
   442     collection isNil ifTrue:[
   442         ^ super nextPutAll:aCollection
   443         super nextPutAll:aCollection.
       
   444         ^ self
   443     ].
   445     ].
   444 
   446 
   445     position1Based := position - ZeroPosition + 1.
   447     position1Based := position - ZeroPosition + 1.
   446 
   448 
   447     nMore := aCollection size.
   449     nMore := aCollection size.
   468         startingAt:1.
   470         startingAt:1.
   469 
   471 
   470     position1Based := position1Based + nMore.
   472     position1Based := position1Based + nMore.
   471     (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
   473     (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
   472     position := position1Based - 1 + ZeroPosition.
   474     position := position1Based - 1 + ZeroPosition.
   473     ^ aCollection
   475     "/ ^ aCollection -- self
   474 !
   476 !
   475 
   477 
   476 nextPutAll:aCollection startingAt:pos1 to:pos2
   478 nextPutAll:aCollection startingAt:pos1 to:pos2
   477     "append some elements of the argument, aCollection to the stream.
   479     "append some elements of the argument, aCollection to the stream.
   478      Redefined to avoid count grows of the underlying collection -
   480      Redefined to avoid count grows of the underlying collection -
   479      instead a single grow on the final size is performed."
   481      instead a single grow on the final size is performed."
   480 
   482 
   481     |nMore final position1Based|
   483     |nMore final position1Based|
   482 
   484 
   483     collection isNil ifTrue:[
   485     collection isNil ifTrue:[
   484 	^ super nextPutAll:aCollection startingAt:pos1 to:pos2
   486         ^ super nextPutAll:aCollection startingAt:pos1 to:pos2
   485     ].
   487     ].
   486 
   488 
   487     position1Based := position - ZeroPosition + 1.
   489     position1Based := position - ZeroPosition + 1.
   488     nMore := pos2 - pos1 + 1.
   490     nMore := pos2 - pos1 + 1.
   489     final := position1Based + nMore - 1.
   491     final := position1Based + nMore - 1.
   490     (writeLimit notNil
   492     (writeLimit notNil
   491     and:[final > writeLimit]) ifTrue:[
   493     and:[final > writeLimit]) ifTrue:[
   492 	final := writeLimit.
   494         final := writeLimit.
   493 	nMore := final - position1Based + 1
   495         nMore := final - position1Based + 1
   494     ].
   496     ].
   495     (final > collection size) ifTrue:[
   497     (final > collection size) ifTrue:[
   496 	self growCollection:final
   498         self growCollection:final
   497     ].
   499     ].
   498 
   500 
   499     collection replaceFrom:position1Based
   501     collection replaceFrom:position1Based
   500 			to:final
   502                         to:final
   501 		      with:aCollection 
   503                       with:aCollection 
   502 		startingAt:pos1.
   504                 startingAt:pos1.
   503 
   505 
   504     position1Based := position1Based + nMore.
   506     position1Based := position1Based + nMore.
   505     (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
   507     (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
   506     position := position1Based - 1 + ZeroPosition.
   508     position := position1Based - 1 + ZeroPosition.
   507     ^ aCollection
   509     "/ ^ aCollection -- return self
   508 
   510 
   509     "
   511     "
   510      |s|
   512      |s|
   511 
   513 
   512      s := '' writeStream.
   514      s := '' writeStream.
   618 ! !
   620 ! !
   619 
   621 
   620 !WriteStream class methodsFor:'documentation'!
   622 !WriteStream class methodsFor:'documentation'!
   621 
   623 
   622 version
   624 version
   623     ^ '$Id: WriteStream.st 10467 2009-08-19 16:14:36Z vranyj1 $'
   625     ^ '$Id: WriteStream.st 10473 2009-10-24 15:48:19Z vranyj1 $'
   624 ! !
   626 !
       
   627 
       
   628 version_CVS
       
   629     ^ '§Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.71 2009/10/05 09:19:55 cg Exp §'
       
   630 ! !
       
   631