[squeak-dev] The Inbox: Collections-ct.950.mcz
Christoph.Thiede at student.hpi.uni-potsdam.de
Wed Jun 30 12:44:29 UTC 2021
> Hmm... I would prefer to just patch Generator instead of Stream:
Not convinced. :-) As far as I understand the general protocol of Streams, #next is expected to answer either the next element, if any, or otherwise, nil. With this knowledge, Stream >> #take: is just erroneous because it will not honor the situation in which the receiver has fewer elements than requested. IMO correctness is more important than optimization.
Nevertheless, I see that for ReadStreams, we can indeed optimize #take:. We just need to map ReadStream >> #take: to #next:, which - unlike its superclass - will not answer more elements than available. Then it should be at least as fast as in the current Trunk.
Do you think this would be the right approach? Shall I upload a new inbox version for this? :-)
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Mittwoch, 30. Juni 2021 11:06:21
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.950.mcz
Hmm... I would prefer to just patch Generator instead of Stream:
s := self environment allClasses readStream.
[s reset; take: 3000] bench
AFTER: '5,700 per second. 175 microseconds per run. 7.59848 % GC time.'
BEFORE: '143,000 per second. 6.99 microseconds per run. 33.90644 % GC time.'
Am 30.06.2021 01:06:49 schrieb commits at source.squeak.org <commits at source.squeak.org>:
A new version of Collections was added to project The Inbox:
==================== Summary ====================
Time: 30 June 2021, 1:06:39.38741 am
Fixes Stream >> #take:. Unlike in #any:, we must not return nil values from #next here but the enumeration earlier. See CollectionsTests-ct.361.
=============== Diff against Collections-mt.945 ===============
Item was changed:
----- Method: Stream>>take: (in category 'collections - accessing') -----
"See Collection protocol."
+ | aCollection |
+ aCollection := OrderedCollection new.
+ maxNumberOfElements timesRepeat: [
+ self atEnd ifTrue: [^ aCollection].
+ aCollection addLast: self next].
+ ^ aCollection!
- ^ self any: maxNumberOfElements!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev