File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -1449,15 +1449,26 @@ proc isNil*[T: proc | iterator {.closure.}](x: T): bool {.noSideEffect, magic: "
14491449 # # Fast check whether `x` is nil. This is sometimes more efficient than
14501450 # # `== nil`.
14511451
1452+ proc supportsCopyMem (t: typedesc ): bool {.magic : " TypeTrait" .}
1453+
14521454when defined (nimHasTopDownInference):
14531455 # magic used for seq type inference
14541456 proc `@` * [T](a: openArray [T]): seq [T] {.magic : " OpenArrayToSeq" .} =
14551457 # # Turns an *openArray* into a sequence.
14561458 # #
14571459 # # This is not as efficient as turning a fixed length array into a sequence
14581460 # # as it always copies every element of `a`.
1459- newSeq (result , a.len)
1460- for i in 0 .. a.len- 1 : result [i] = a[i]
1461+ let sz = a.len
1462+ when supportsCopyMem (T) and not defined (js):
1463+ result = newSeqUninit [T](sz)
1464+ when nimvm :
1465+ for i in 0 .. sz- 1 : result [i] = a[i]
1466+ else :
1467+ if sz != 0 :
1468+ copyMem (addr result [0 ], addr a[0 ], sizeof (T) * sz)
1469+ else :
1470+ newSeq (result , sz)
1471+ for i in 0 .. sz- 1 : result [i] = a[i]
14611472else :
14621473 proc `@` * [T](a: openArray [T]): seq [T] =
14631474 # # Turns an *openArray* into a sequence.
@@ -1628,8 +1639,6 @@ when not defined(js) and defined(nimV2):
16281639 vTable: UncheckedArray [pointer ] # vtable for types
16291640 PNimTypeV2 = ptr TNimTypeV2
16301641
1631- proc supportsCopyMem (t: typedesc ): bool {.magic : " TypeTrait" .}
1632-
16331642when notJSnotNims and defined (nimSeqsV2):
16341643 include " system/strs_v2"
16351644 include " system/seqs_v2"
You can’t perform that action at this time.
0 commit comments