Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
The copyWithin works like C and C++'s memmove, and is a high-performance method to shift the data of an Array. This especially applies to the TypedArray method of the same name. The sequence is copied and pasted as one operation; pasted sequence will have the copied values even when the copy and paste region overlap.
scratch below
moveRange(a: var openArray[T], r: HSclice[int], newStart: int) + copyRange
moveMem
T
example use cases
implementation
refs https://github.com/nim-lang/Nim/pull/16484#issuecomment-751669056 could be in some std/memory or std/memutils in js use
copyWithin
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithinscratch below
moveRange(a: var openArray[T], r: HSclice[int], newStart: int)
+copyRange
setSlice
in https://github.com/nim-lang/Nim/pull/16280