-
Notifications
You must be signed in to change notification settings - Fork 11
Description
in Nim 2.0, shallowCopy will be removed. This means every occurrence of shallowCopy in the library must be replaced by something else.
See: nim-lang/Nim#20017
For simple situations, sink may be good enough:
e.g.
proc init*[T](b: var Buffer[T], d: T) =
shallowCopy(b.data, d)
b.offset = 0becomes
proc init*[T](b: var Buffer[T], d: sink T) =
b.data = d
b.offset = 0The compiler will then decide whether to move or copy the data depending on whether it can prove that buf.init(s) is the last usage of s or not.
However, there are some problems:
-
If the compiler decides to copy, then there will be a performance hit. To keep good performance in this case, I believe some sort of buffer-via-pointer is needed, e.g. trick's View or collections' View or Nim's experimental view types.
-
There are some uses of
shallowCopyin the codebase that don't neatly fit thesinkpattern, e.g.shallowCopy(png.apngPixels[0], png.pixels) frameConvert[T](png, modeIn, modeOut, png.width, png.height, 0, state) shallowCopy(png.pixels, png.apngPixels[0])
(edit, maybe they can be solved like this?)
png.apngPixels[0] = move(png.pixels) frameConvert[T](png, modeIn, modeOut, png.width, png.height, 0, state) png.pixels = move(png.apngPixels[0])