#replaceFrom:to:with:startingAt: vs. memmove()

Lukas Renggli renggli at gmail.com
Wed Oct 17 17:41:39 UTC 2007


As far as I see, the only obvious and efficient way to copy parts of
SequencableCollection's around is to use
#replaceFrom:to:with:startingAt:.

The problem is that for overlapping regions this does not work:

    " copying ahead works "
    buffer := String withAll: ($a to: $j).
    buffer replaceFrom: 1 to: 9 with: buffer startingAt: 2.
    self assert: buffer = 'bcdefghijj'.

    " copying backwards fails: the result is 'aaaaaaaaaa' "
    buffer := String withAll: ($a to: $j).
    buffer replaceFrom: 2 to: 10 with: buffer startingAt: 1.
    self assert: buffer = 'aabcdefghi'. "

When realizing this issue I felt put back far into the era of memcpy()
vs. memmove().

Fixing the fallback code in Smalltalk is obviously trivial, if
primitive 105 (that is flawed as well) was not involved. I wonder if
this never caused any troubles during the past 25 years? Why not fix
it? Afraid of the slowdown of an additional #== check?

Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch



More information about the Squeak-dev mailing list