[squeak-dev] replaceFrom:to:with:startingAt:

Eliot Miranda eliot.miranda at gmail.com
Tue Sep 23 21:55:24 UTC 2014


On Mon, Sep 22, 2014 at 2:16 PM, Bert Freudenberg <bert at freudenbergs.de>
wrote:

>
> On 22.09.2014, at 22:47, Nicolas Cellier <
> nicolas.cellier.aka.nice at gmail.com> wrote:
>
>
>
> 2014-09-22 22:34 GMT+02:00 Bert Freudenberg <bert at freudenbergs.de>:
>
>>
>> On 22.09.2014, at 22:21, Ron Teitelbaum <ron at usmedrec.com> wrote:
>>
>> >
>> >> From: Bert Freudenberg
>> >> Sent: Monday, September 22, 2014 4:00 PM
>> >>
>> >> I just found out why PNG decoding was broken in SqueakJS [*]. Wouldn't
>> >> have believed that any code actually relied on the following behavior:
>> >>
>> >>      | a |
>> >>      a := (1 to: 20) asArray.
>> >>      a replaceFrom: 11 to: 20 with: a startingAt: 8.
>> >>
>> >>      ==> #(1 2 3 4 5 6 7 8 9 10 8 9 10 8 9 10 8 9 10 8)
>> >>
>> > That's funky!  Hope it wasn't my code!  Seems wrong to not copy the
>> array
>> > before modifying it  (Like your buggy VM did).
>>
>> It's not a copy. It moved the numbers 8-17 to index 11. Which is what I
>> erroneously had assumed to be the desired behavior.
>>
>> - Bert -
>>
>>
> It's a known problem.
> The primitive should use memmove rather than memcpy.
> So the solution is quite simple, it's just that it's waiting for a good
> soul to integrate it.
>
>
> What I'm saying is that there is code which will actually fail in subtle
> ways if we change that behavior. The LZW decode *relies* on this. If we
> change the primitive it would fail.
>
> So rather than changing what the "stringReplace" primitive does we might
> rather want to add a "stringMove" primitive.
>

+1.  An implement a move family, e.g.


SequenceableCollection>>moveFrom: start to: stop with: replacement
startingAt: repStart
| index repOff |
repOff := repStart - start.
start > repStart
ifTrue:
[index := stop + 1.
 [(index := index - 1) >= start] whileTrue:
[self at: index put: (replacement at: repOff + index)]]
ifFalse:
[index := start - 1.
 [(index := index + 1) <= stop] whileTrue:
[self at: index put: (replacement at: repOff + index)]]

But more reasonably

SequenceableCollection>>moveFrom: start to: stop to: repStart
| index repOff |
repOff := repStart - start.
start > repStart
ifTrue:
[index := stop + 1.
 [(index := index - 1) >= start] whileTrue:
[self at: index put: (self at: repOff + index)]]
ifFalse:
[index := start - 1.
 [(index := index + 1) <= stop] whileTrue:
[self at: index put: (self at: repOff + index)]]


Btw, BitBlt has "move" semantics and I believe this is even used in some
> places (via #hackBits:).
>

Yes, you're right.  But I think there was a time when you could turn that
off and get interesting effects :-).



> - Bert -
>
>
>
>
>
>> > Ron
>> >
>> >> In my (buggy) VM it answered
>> >>
>> >>      ==> #(1 2 3 4 5 6 7 8 9 10 8 9 10 11 12 13 14 15 16 17)
>> >>
>> >> which apparently did not at all match what The Creators intended ;)
>> >>
>> >> - Bert -
>> >>
>> >> [*] specifically, #decompressBlock:with:
>> >
>> >
>>
>>
>>
>>
>>
>>
>
>
>
>
>
>
>
>


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20140923/f9e835ec/attachment.htm


More information about the Squeak-dev mailing list