timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

type-safe moveMem, copyMem overloads with `openArray` #455

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

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/copyWithin

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

timotheecour commented 3 years ago

use it in:

timotheecour commented 3 years ago

use it in: