<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 23, 2017 at 10:49 PM, Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@caesar.elte.hu" target="_blank">leves@caesar.elte.hu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br>On Fri, 22 Dec 2017, Clément Bera wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hi all,<br>
</blockquote>
<br>
snip<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
1. translate: aString from: start  to: stop  table: table<br>
<br>
This primitive seems to be unused. I suggest we move it from a primitive <br>
</blockquote>
to plain Smalltalk code.<br>
<br>
That primitive is currently used to convert ByteStrings to lower and upper case, and it's also used to convert between cr and lf line endings. The primitive fails in Pharo for some reason, but it's still used in the 6.0 image I have.<br>
It works properly in Squeak and Cuis.<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
2. stringHash: aString initialHash: speciesHash<br>
<br>
Since we now have hashMultiply as a primitive, the stringHash primitive <br>
</blockquote>
is now faster for very small strings with a Smalltalk version using hashMultiply, and slower (2x) on medium to large strings. I suggest we move it to plain Smalltalk code.<br>
<br>
In my 64-bit Squeak Spur image, the primitive is faster than the pure Smalltalk code (which uses the new hashMultiply primitive) for strings of length 4 and longer. The longer the string, the more significant the different becomes, probably due to the more frequent use of the hashMultiply primitive (for a string of length 1000, it's used 1000 times).<br>
<br>
Here's the benchmark I wrote:<br>
<br>
data := #(0 1 2 3 4 5 10 20 50 100 200 500 1000) collect: [ :size |<br>
        | s primitive smalltalk overhead iterations |<br>
        Smalltalk garbageCollect.<br>
        s := String new: size withAll: $a.<br>
        iterations := 100000000 // (size max: 1).<br>
        overhead := [ 1 to: iterations do: [ :i | ] ] timeToRun.<br>
        primitive := [ 1 to: iterations do: [ :i | ByteString stringHash: s initialHash: 1 ] ] timeToRun.<br>
        smalltalk := [ 1 to: iterations do: [ :i | ByteString stringHash2: s initialHash: 1 ] ] timeToRun.<br>
        { size. primitive - overhead. smalltalk - overhead } ].<br>
<br>
So, I suggest the primitive be kept in some form.<br>
<br>
<br>
What I always wanted to see is a linear search primitive. Something like primitiveIndexOfAsciiInString, but more general:<br>
- it should use #== for comparison<br>
- it should return a number according to the following rules<br>
  - return the (one-based) index of the first indexable field containing the value if such exists<br>
  - return the (one-based) index of the first pointer field containing the value times -1 if such exists<br>
  - return 0 otherwise<br>
We actually have a primitive for this, primitive 132, but it returns a boolean value instead of the actual index, which makes it far less useful than what it could be.<br>
<br></blockquote><div><br></div><div>Thing is instVarAt: works for everything</div><div><font face="monospace, monospace">#[10] instVarAt: 1 => 10</font></div><div><font face="monospace, monospace">#(10) instVarAt: 1 => 10</font></div><div>So why having negative values ?</div><div>Could it only answer a positive index or 0 and never a negative index ?</div><div>Especially I think this makes most sense for variable objects, data or pointers, and I don't think negative values there makes sense.</div><div> </div><div>I don't really mind having a more generic numbered primitiveIndexOfAsciiInString instead of a string specific one.</div><div><br></div><div>Maybe <font face="monospace, monospace">#indexOf: value startingAt: startInteger to: lastInteger</font></div><div><font face="monospace, monospace"><br></font></div><div>So it can be used easily for OrderedCollection too:</div><div><div><font face="monospace, monospace">OrderedCollection>>#indexOf: anElement startingAt: start ifAbsent: exceptionBlock</font>    </div><div><span style="font-family:monospace,monospace;white-space:pre">        </span>^(index := array </div><div><span style="font-family:monospace,monospace;white-space:pre">    </span><span style="font-family:monospace,monospace;white-space:pre">     </span><span style="font-family:monospace,monospace">indexOf: </span><span style="font-family:monospace,monospace">anElement</span><span style="font-family:monospace,monospace"> </span></div><div><span style="font-family:monospace,monospace;white-space:pre">        </span><span style="font-family:monospace,monospace;white-space:pre">     </span><span style="font-family:monospace,monospace">startingAt: </span><span style="font-family:monospace,monospace">firstIndex + start - 1</span><span style="font-family:monospace,monospace"> </span></div><div><span style="font-family:monospace,monospace;white-space:pre">        </span><span style="font-family:monospace,monospace;white-space:pre">     </span><span style="font-family:monospace,monospace">to: lastIndex) = 0 </span></div><div><span style="font-family:monospace,monospace;white-space:pre">       </span><span style="font-family:monospace,monospace;white-space:pre">     </span><span style="font-family:monospace,monospace;white-space:pre">     </span>ifTrue: [<span style="font-family:monospace,monospace">exceptionBlock value</span>]</div><div><span style="font-family:monospace,monospace;white-space:pre">     </span><span style="font-family:monospace,monospace;white-space:pre">     </span><span style="font-family:monospace,monospace;white-space:pre">     </span>ifFalse: [<span style="font-family:monospace,monospace">index</span>]</div></div><div>instead of:</div><div><div><font face="monospace, monospace">OrderedCollection>>#indexOf: anElement startingAt: start ifAbsent: exceptionBlock</font></div><div><font face="monospace, monospace"><span style="white-space:pre">   </span>firstIndex + start - 1 to: lastIndex do: [ :index |</font></div><div><font face="monospace, monospace"><span style="white-space:pre">            </span>(array at: index) = anElement ifTrue: [ ^index - firstIndex + 1 ] ].</font></div><div><font face="monospace, monospace"><span style="white-space:pre">   </span>^exceptionBlock value</font></div></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Levente<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span style="font-size:12.8px">Clément Béra</span><div style="font-size:12.8px">Pharo consortium engineer</div><div style="font-size:12.8px"><a href="https://clementbera.wordpress.com/" target="_blank">https://clementbera.wordpress.com/</a><br></div><div style="font-size:12.8px"><span style="line-height:16px">Bâtiment B 40, avenue Halley 59650 </span><span style="font-weight:bold;line-height:16px">Villeneuve d'Ascq</span></div></div></div>
</div></div>