Skip to content

Instantly share code, notes, and snippets.

@Araq
Created May 14, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Araq/d7771b542ec759d664f2be65b107d4ec to your computer and use it in GitHub Desktop.
Save Araq/d7771b542ec759d664f2be65b107d4ec to your computer and use it in GitHub Desktop.
when defined(nimOpMove):
proc `=move`[T](x, y: var seq[T]) =
mixin `=destroy`
if a.p != b.p:
var a = cast[ptr NimSeqV2[T]](addr x)
var b = cast[ptr NimSeqV2[T]](addr y)
if a.p != nil: `=destroy`(x)
a.len = b.len
a.p = b.p
# p is stolen, so afterwards it must be nil
b.p = nil
else:
proc `=sink`[T](x: var seq[T]; y: seq[T]) =
mixin `=destroy`
var a = cast[ptr NimSeqV2[T]](addr x)
var b = cast[ptr NimSeqV2[T]](unsafeAddr y)
if a.p != nil and a.p != b.p:
`=destroy`(x)
a.len = b.len
a.p = b.p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment