<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
                                        Hi Christoph,<div><br></div><div>thanks for checking. Sounds good. :-) Both your proposed bugfix and the overall refactoring to preserve the performance in read-streams.</div><div><br></div><div>Best,</div><div>Marcel</div><div class="mb_sig"></div><blockquote class='history_container' type='cite' style='border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;'>
                        <p style='color: #AAAAAA; margin-top: 10px;'>Am 30.06.2021 16:00:52 schrieb Thiede, Christoph <christoph.thiede@student.hpi.uni-potsdam.de>:</p><div style='font-family:Arial,Helvetica,sans-serif'>

<div id="divtagdefaultwrapper" style="font-size: 12pt;color: #000000;font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi Marcel,</p>
<p><br>
</p>
<p>the bug manifests itself in Generator, yes, but for the reasons I tried to explain before, I think that the defect is indeed located in Stream.</p>
<p><br>
</p>
<p>> <span style="font-size: 12pt">Please double-check what the correct subclass of Stream should be. I think that ReadStream is too specific.</span></p>
<div><br>
</div>
<p></p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt;color: rgb(0, 0, 0);font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols">
<div name="divtagdefaultwrapper" style="font-family: Calibri,Arial,Helvetica,sans-serif;font-size: ;margin: 0">
<div>
<div class="_rp_T4" id="Item.MessagePartBody">
<div class="_rp_U4 ms-font-weight-regular ms-font-color-neutralDark rpHighlightAllClass rpHighlightBodyClass" id="Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="divtagdefaultwrapper"><span style="font-family: Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont">
<div><font size="3" color="black"><span style="font-size: 12pt"><a href="http://www.hpi.de/" target="_blank" rel="noopener noreferrer" id="LPNoLP"><font size="2"><span id="LPlnk909538"><font color="#757B80"></font></span></font></a></span></font></div>
</font></div>
</div>
</span></div>
</div>
</div>
</div>
<div class="_rp_T4" id="Item.MessagePartBody">The problem with PositionableStream is that its implementation of #next: still answers a collection with exactly n elements some of which might be excess values (nil). ReadStream is the first class in the inheritance
 line in which #next: automatically stops the enumeration at the end of the receiver and thus behaves like #take:. Given a hypothetical alternative subclass of PositionableStream which is neither ReadStream nor WriteStream (i.e., let's imagine a decorator class
 for another stream), it might be affected by the discrepancy between #next: and take: as well. For this reason, I think we should only apply the optimization of #take: to ReadStream.</div>
<div class="_rp_T4" id="Item.MessagePartBody"><br>
</div>
<div class="_rp_T4" id="Item.MessagePartBody">What do you think? :-)</div>
<div class="_rp_T4" id="Item.MessagePartBody"><br>
</div>
<div class="_rp_T4" id="Item.MessagePartBody">Best,</div>
<div class="_rp_T4" id="Item.MessagePartBody">Christoph</div>
</div>
<div><span style="font-size: 10pt;color: #808080"></span></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif;color: #000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel<br>
<b>Gesendet:</b> Mittwoch, 30. Juni 2021 14:53:24<br>
<b>An:</b> squeak-dev<br>
<b>Betreff:</b> Re: [squeak-dev] The Inbox: Collections-ct.950.mcz</span>
<div> </div>
</div>
<div>
<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
Hi Christoph,
<div><br>
</div>
<div>you found a bug in Generator, not ReadStream nor WriteStream. Both work as expected. ;-) That's why the simplest fix would be in Generator.</div>
<div><br>
</div>
<div>Yes, we can change the default behavior as you proposed and overwrite it in PositionableStream for better performance. Please double-check what the correct subclass of Stream should be. I think that ReadStream is too specific.</div>
<div><br>
</div>
<div>Best,</div>
<div>Marcel</div>
<div class="mb_sig"></div>
<blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
<p style="color: #AAAAAA; margin-top: 10px;">Am 30.06.2021 14:44:41 schrieb Thiede, Christoph <christoph.thiede@student.hpi.uni-potsdam.de>:</p>
<div style="font-family:Arial,Helvetica,sans-serif">
<div id="divtagdefaultwrapper" style="font-size: 12pt;color: #000000;font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi Marcel,</p>
<p><br>
</p>
<p>> <span style="font-size: 12pt">Hmm... I would prefer to just patch Generator instead of Stream:</span></p>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Do you think this would be the right approach? Shall I upload a new inbox version for this? :-)</div>
<div><br>
</div>
<div>Best,</div>
<div>Christoph</div>
<p></p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt;color: rgb(0, 0, 0);font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols">
<div name="divtagdefaultwrapper" style="font-family: Calibri,Arial,Helvetica,sans-serif;font-size: ;margin: 0">
<div><span style="font-size: 10pt;color: #808080"></span></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif;color: #000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel<br>
<b>Gesendet:</b> Mittwoch, 30. Juni 2021 11:06:21<br>
<b>An:</b> squeak-dev<br>
<b>Betreff:</b> Re: [squeak-dev] The Inbox: Collections-ct.950.mcz</span>
<div> </div>
</div>
<div>
<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
Hmm... I would prefer to just patch Generator instead of Stream:
<div><br>
</div>
<div>
<div><span style="font-size: 13.3333px">s := self environment allClasses readStream.</span></div>
<div><span style="font-size: 13.3333px">[s reset; take: 3000] bench</span></div>
<div><span style="font-size: 13.3333px"><br>
</span></div>
<div><span style="font-size: 13.3333px">AFTER: '5,700 per second. 175 microseconds per run. 7.59848 % GC time.' </span></div>
<div><span style="font-size: 13.3333px">BEFORE: '143,000 per second. 6.99 microseconds per run. 33.90644 % GC time.' </span></div>
</div>
<div><span style="font-size: 13.3333px"><br>
</span></div>
<div><span style="font-size: 13.3333px">Best,</span></div>
<div><span style="font-size: 13.3333px">Marcel</span></div>
<div class="mb_sig"></div>
<blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
<p style="color: #AAAAAA; margin-top: 10px;">Am 30.06.2021 01:06:49 schrieb commits@source.squeak.org <commits@source.squeak.org>:</p>
<div style="font-family:Arial,Helvetica,sans-serif">A new version of Collections was added to project The Inbox:<br>
http://source.squeak.org/inbox/Collections-ct.950.mcz<br>
<br>
==================== Summary ====================<br>
<br>
Name: Collections-ct.950<br>
Author: ct<br>
Time: 30 June 2021, 1:06:39.38741 am<br>
UUID: 58b871bc-ace9-184b-8e98-305453096350<br>
Ancestors: Collections-mt.945<br>
<br>
Fixes Stream >> #take:. Unlike in #any:, we must not return nil values from #next here but the enumeration earlier. See CollectionsTests-ct.361.<br>
<br>
=============== Diff against Collections-mt.945 ===============<br>
<br>
Item was changed:<br>
----- Method: Stream>>take: (in category 'collections - accessing') -----<br>
take: maxNumberOfElements<br>
"See Collection protocol."<br>
+ <br>
+ | aCollection |<br>
+ aCollection := OrderedCollection new.<br>
+ maxNumberOfElements timesRepeat: [<br>
+ self atEnd ifTrue: [^ aCollection].<br>
+ aCollection addLast: self next].<br>
+ ^ aCollection!<br>
- <br>
- ^ self any: maxNumberOfElements!<br>
<br>
<br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div></blockquote>
                                        </div></body>