I was thinking about refs too and I kinda doubt that just moving the refs in 
memory works. Sequtils usually uses `shallowCopy()` for manipulation of 
elements in the seq. Which imho avoids (deep) copying a string or seq inside 
the seq and copies the "pointer" (reference). I guess OP shift() proc does not 
work very well for strings and seq types as they will be copied when only using 
`=`.

Looking at `delete()` in sequtils one also sees that there is nothing obviously 
done to delete entries. But this is probably part of `shallowCopy()` and maybe 
also part of `setLen()`. I did not dig into it but looking at it makes me think 
that simple memory manipulation is not enough. I still wonder if it would be ok 
(and faster) with non ref types in the seq.

Maybe the code from @stisa does work without refs or even with refs... maybe 
needing the addition of something like `shallowCopy()` to move the second 
element into the first elements position before the memory move to "free" the 
former first element correctly. Maybe one needs to unref() it.. or that whole 
thought is stupid :)

I guess some people here know more about the internals and can answer if and 
when it works and if it partly would work, why it is not used in sequtils() for 
example.

It just feels "strange" that there is a solid memory block and then one does 
move element by element instead of doing what one would do in C...

Reply via email to