NeoCSV icon indicating copy to clipboard operation
NeoCSV copied to clipboard

use stream's nextPutAll:

Open vonbecmann opened this issue 3 years ago • 4 comments

what do you think?

vonbecmann avatar Sep 25 '22 00:09 vonbecmann

it works because reader implements do:

vonbecmann avatar Sep 25 '22 01:09 vonbecmann

That is very clever ;-)

Now, it depends on a particular implementation of #nextPutAll: (the one in Stream). Looking at all implementations, I see some which would probably fail.

On the other hand, in this case we only need what #streamContents: uses.

The question remains if this change would improve the clarity of this already simple code, or obscure it.

svenvc avatar Sep 26 '22 09:09 svenvc

good question. i debug the following example (NeoCSVReader on: '"1",,"3"' readStream) upToEnd and it depends on WriteStream>>nextPutAll: and given the first stmt collection class == aCollection class ifFalse: [^ super nextPutAll: aCollection ]. it goes to

Stream>>#nextPutAll: aCollection 
	"Append the elements of aCollection to the sequence of objects accessible 
	by the receiver. Answer aCollection."
	
	aCollection do: [:v | self nextPut: v].
	^aCollection

and then goes to WriteStream>>#nextPut:. the message send is longer with more dependencies. the previous version had one dependency WriteStream>>#nextPut: in any case it always depends on WriteStream(Collections-Streams).

vonbecmann avatar Sep 26 '22 23:09 vonbecmann

just showing off a clever hack.

vonbecmann avatar Sep 26 '22 23:09 vonbecmann