<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-05-04 22:10 GMT+02:00 Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@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"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Fri, May 4, 2018 at 12:44 PM, Nicolas Cellier <span dir="ltr"><<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@<wbr>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>2018-05-04 0:50 GMT+02:00 Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Tobias, Hi All,<br>
<span class="m_-5017087104009003576m_-2524124307376450180gmail-"><br>
<br>
> On May 3, 2018, at 3:08 PM, Levente Uzonyi <<a href="mailto:leves@caesar.elte.hu" target="_blank">leves@caesar.elte.hu</a>> wrote:<br>
> <br>
>> On Thu, 3 May 2018, Tobias Pape wrote:<br>
>> <br>
>> <br>
>>> On 03.05.2018, at 22:48, Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmai<wbr>l.com</a>> wrote:<br>
>>> But WideString requires another hack...<br>
>> <br>
>> Like<br>
>> <br>
>>    ^false<br>
>> <br>
>> ? :D<br>
> <br>
> Not really: ((WideString new: 2) first: 1) isAsciiString<br>
> <br>
> Levente<br>
<br>
</span>Note that this is a common issue in Smalltalk, where we can have different implementations (classes) with the same interface.  Take LargeInteger and SmallInteger.  The arithmetic system and the VM are both implemented to almost never represent something in the SmallInteger range as a LargeInteger (there are rare circumstances but it's safe to assume that the invariant is always maintained, and the invariant is depended upon).  This allows the VM to only ever check for SmallIntegers for things like indices, never having to waste code bloat or cycles checking for denormalised LargeIntegers.<br>
<br>
Why can we do this with SmallInteger & LargeInteger, but not with ByteString and WideString?  Because ByteString and WideString are mutable (and because of the FFI).  Were the system to maintain the invariant that strings containing characters in the range 0 to 255 were always represented by ByteString, then, Tobias, your WideString>>isAsciiString ^false would work.  But the cost of maintaining that invariant would be scanning the ret of the string every time at:put: deposited a byte character, to see if we had just replaced the last wide character by a byte one and hence needed to do a become:.  We'd also potentially spend a lot of time doing becomes, and we'd also have to allow for denormalisation when passing an ascii string through the FFI to code requiring a wide string.  And even worse we'd have to avoid WideString new: n like the plague since new strings are always ascii, being full of nuls.  So only WideString with:... forms would make sense.<br>
<br></blockquote></span><div>In such case we would maintain a count of non-byte characters and avoid scanning...<br></div></div></div></div></blockquote><div><br></div></span><div>Only possible if the representation makes room for a count, which could easily require more than 24 bits.  It is non-trivialto implement, and of course slows down access.</div><span class=""><div><br></div></span></div></div></div></blockquote><div><br></div><div>For example, just allocate one more character code and use it to store the count...<br></div><div>Most could be done at image side.<br><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
So this kind of multiple implementation approach only works well with certain types and access patterns.  Interesting, no?<br></blockquote></span></div></div></div></blockquote></span></div><br><div class="m_-5017087104009003576gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>
<br><br>
<br></blockquote></div><br></div></div>