<div dir="ltr"><div><div>Just for musing with stupid implementations:<br><br>CharacterSet>>ascii<br>    "return a set containing just the ASCII characters"<br>    ^Ascii ifNil: [ Ascii := self newFrom: ((1 to: 127) collect: [:code | code asCharacter]) ]<br>CharacterSet>>nonAscii<br>    ^NonAscii ifNil: [ NonAscii := self ascii complement ].<br><br>| bsa |<br>bsa := ByteString allInstances.<br>{<br>[bsa do: [:e | e isAsciiString]] bench.<br>[bsa do: [:e | (CharacterSet nonAscii findFirstInByteString: e startingAt: 1) = 0]] bench.<br>}.<br> #('2.88 per second. 348 milliseconds per run.' '36.1 per second. 27.7 milliseconds per run.')<br><br>So we could do this for ByteString:<br><br>ByteString>>isAsciiString<br>    ^(CharacterSet nonAscii findFirstInByteString: self startingAt: 1) = 0<br><br></div><div>But WideString requires another hack...<br><br></div></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2018-05-03 22:11 GMT+02:00 karl ramberg <span dir="ltr"><<a href="mailto:karlramberg@gmail.com" target="_blank">karlramberg@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Thu, May 3, 2018 at 10:09 PM, karl ramberg <span dir="ltr"><<a href="mailto:karlramberg@gmail.com" target="_blank">karlramberg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm all for faster code in the standard library.<div>One could leave the old version in the comment as an example for other ways of writing it.</div><div><br></div></div></blockquote></span><div>

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Which he already did.</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Why complain about it then :-(</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Best,</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Karl</div><br class="m_3593550707415783690gmail-Apple-interchange-newline">

 </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>Best,</div><div>Karl</div><div><br></div></div><div class="m_3593550707415783690HOEnZb"><div class="m_3593550707415783690h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 3, 2018 at 7:51 PM, Chris Cunningham <span dir="ltr"><<a href="mailto:cunningham.cb@gmail.com" target="_blank">cunningham.cb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Thu, May 3, 2018 at 10:34 AM, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Thu, May 3, 2018 at 10:12 AM, Chris Muller <span dir="ltr"><<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">+1.  Not only that, why the call to #basicSize and #basicAt:.  Really?<br>
<br>
It's like...  not even Smalltalk anymore...   :(<br></blockquote><div><br></div></span><div>What?  This is a workhorse method, and you want to create a block, and apply the block to each element, and convert each element from a character to an integer, when basicAt: yields (and has always yielded) integers in strings?  You think that one line with a block and a high-level iterator is so much better than a two line with a simpler inner loop?</div><div> </div><div><div>| strings nothing allSatisfy basicAt |</div><div>strings := String allSubInstances.</div><div>strings := strings, strings, strings, strings, strings.</div><div>nothing := [:s|].</div><div>allSatisfy := [:s| s isAsciiStringWithAllSatisfy].</div><div>basicAt := [:s| s isAsciiStringWithBasicAt].</div><div>Smalltalk garbageCollect.</div><div>1 to: 2 do:</div><div><span class="m_3593550707415783690m_-2419342603620482340m_-4146867987906159694m_-1230378789376810188gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>[:ign| times := { nothing. allSatisfy. basicAt } collect: [:block| [strings do: block] timeToRun]].</div><div>(times second - times first / (times third - times first) asFloat) roundTo: 0.1</div><div><br></div><div>Answers range from 5.1 to 5.7 on 64-bits Mac OS X.</div></div><div><br></div><div>You really want that elegance for something that is 5 times slower but one line shorter?  I did this because I saw Patrick inline isAsciiString in mail message processing, and I thought a) his method would read better if it used isAsciiString, and b) isAsciiString can be implemented much better without affecting clients, so I went ahead.  Part of the beauty of Smalltalk is that clients are insulated from implementation so that implementations can be improved.  Since when has that not been a part of Smalltalk?</div><div><div class="m_3593550707415783690m_-2419342603620482340m_-4146867987906159694h5"><div><br></div></div></div></div></div></div></blockquote></span><div>While I understand (and like) the idea of having nice, clean, elegant methods everywhere in Squeak, I also would like it to be super fast.  I think Eliot's change is a nice example straddling that line - note the elegant way, and then show (and implement) a fast way to do the same thing still just using Smalltalk.</div><div><br></div><div>Not to mention that he actually commented the method with what it should do.</div><div><br></div><div>-cbc</div></div></div></div>
<br><br>
<br></blockquote></div><br></div>
</div></div></blockquote></span></div><br></div></div>
<br><br>
<br></blockquote></div><br></div>