<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body style="font-family:Arial;font-size:14px">
<p>Quoting Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;:</p>
<blockquote style="border-left:2px solid blue;margin-left:2px;padding-left:12px;" type="cite">
<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">
<p>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 'Content-Type' and 'Content-Length'. 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.</p>
</blockquote>
<div>&nbsp;</div>
<div>Why not rewrite</div>
<div>&nbsp;</div>
<div>String&gt;&gt;= aString&nbsp;</div>
<div>"Answer whether the receiver sorts equally as aString.</div>
<div>The collation order is simple ascii (with case differences)."</div>
<div>aString isString ifFalse: [ ^ false ].</div>
<div>^ (self compare: self with: aString collated: AsciiOrder) = 2</div>
<div>&nbsp;</div>
<div>as</div>
<div>&nbsp;</div>
<div>
<div>String&gt;&gt;= aString&nbsp;</div>
<div>"Answer whether the receiver sorts equally as aString.</div>
<div>The collation order is simple ascii (with case differences)."</div>
<div>&nbsp;</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].</div>
<div>^ (self compare: self withSize: with: aString collated: AsciiOrder) = 2</div>
</div>
<div>&nbsp;</div>
<div>?</div>
</div>
<div class="gmail_extra">&nbsp;</div>
One /could/ add a replacement compare:with:collated: primitive&nbsp;primitiveCompareString which took the sizes as arguments to avoid asking twice. &nbsp;But it wouldn't be safe. &nbsp;One could abuse the primitive and lie about the size. &nbsp;So I suspect it is best to add the size check to String&gt;&gt;#= and accept the duplication of the&nbsp;primitive&nbsp;finding the sizes of the two strings. &nbsp;The cost in the primitive is minimal. &nbsp;A WideString version of the primitive might pay its way, but if Spur and Sista arrive soon the primitive shouldn't be faster than the optimised Smalltalk code.<br>
--<br>
best,
<div>Eliot</div>
</div>
</div>
</blockquote>
<p>BTW, any good reason for not prefixing all the implementors of #= with this?<br>
<br>
"Any object is equal to itself"<br>
self == argument ifTrue: [ ^ true ].<br></p>
<div>Cheers,<br>
Juan Vuletich</div>
</body>
</html>