<div dir="ltr">Hi Phillipe,<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 26, 2014 at 12:51 AM, Philippe Marschall <span dir="ltr">&lt;<a href="mailto:philippe.marschall@netcetera.ch" target="_blank">philippe.marschall@netcetera.ch</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi<br>
<br>
I have been investigating why Dictionary look up performance with String keys is not as good as I would expected. Something I noted is that String &gt;&gt; #= is implemented in terms of #compare:with:collated:. There is no short circuit if Strings are not the same size. In my case some Strings have the same prefix but a different length eg &#39;Content-Type&#39; and &#39;Content-Length&#39;. In that case a #compare:with:collated: is performed even though we know in advance the answer will be false because they have different sizes.<br>
</blockquote><div><br></div><div>Why not rewrite</div><div><br></div><div>String&gt;&gt;= aString </div><div><span class="" style="white-space:pre">        </span>&quot;Answer whether the receiver sorts equally as aString.</div>
<div><span class="" style="white-space:pre">        </span>The collation order is simple ascii (with case differences).&quot;</div><div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">        </span>aString isString ifFalse: [ ^ false ].</div>
<div><span class="" style="white-space:pre">        </span>^ (self compare: self with: aString collated: AsciiOrder) = 2</div><div><br></div><div>as</div><div><br></div><div><div>String&gt;&gt;= aString </div><div><span class="" style="white-space:pre">        </span>&quot;Answer whether the receiver sorts equally as aString.</div>
<div><span class="" style="white-space:pre">        </span>The collation order is simple ascii (with case differences).&quot;</div><div><br></div><div><span style="white-space:pre">        (</span>aString isString</div><div><span style="white-space:pre">         and: [self size = aString size]) i</span>fFalse: [^false].<br>
</div><div><span class="" style="white-space:pre">        </span>^ (self compare: self withSize: with: aString collated: AsciiOrder) = 2</div></div><div><br></div><div>?</div><div></div></div><div class="gmail_extra"><br></div>One /could/ add a replacement compare:with:collated: primitive primitiveCompareString which took the sizes as arguments to avoid asking twice.  But it wouldn&#39;t be safe.  One could abuse the primitive and lie about the size.  So I suspect it is best to add the size check to String&gt;&gt;#= and accept the duplication of the primitive finding the sizes of the two strings.  The cost in the primitive is minimal.  A WideString version of the primitive might pay its way, but if Spur and Sista arrive soon the primitive shouldn&#39;t be faster than the optimised Smalltalk code.<br>
-- <br>best,<div>Eliot</div>
</div></div>