File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -1465,15 +1465,27 @@ proc isNil*[T: proc | iterator {.closure.}](x: T): bool {.noSideEffect, magic: "
1465
1465
# # Fast check whether `x` is nil. This is sometimes more efficient than
1466
1466
# # `== nil`.
1467
1467
1468
+ proc supportsCopyMem(t: typedesc ): bool {.magic: " TypeTrait" .}
1469
+
1468
1470
when defined(nimHasTopDownInference):
1469
1471
# magic used for seq type inference
1470
1472
proc `@` * [T](a: openArray [T]) : seq [T] {.magic: " OpenArrayToSeq" .} =
1471
1473
# # Turns an *openArray* into a sequence.
1472
1474
# #
1473
1475
# # This is not as efficient as turning a fixed length array into a sequence
1474
1476
# # as it always copies every element of `a`.
1475
- newSeq(result , a.len)
1476
- for i in 0 .. a.len- 1 : result [i] = a[i]
1477
+ let sz = a.len
1478
+ when supportsCopyMem(T) and not defined(js):
1479
+ when nimvm :
1480
+ newSeq(result , sz)
1481
+ for i in 0 .. sz- 1 : result [i] = a[i]
1482
+ else :
1483
+ result = newSeqUninit[T](sz)
1484
+ if sz != 0:
1485
+ copyMem(addr result [ 0], addr a[0 ], sizeof(T) * sz)
1486
+ else :
1487
+ newSeq(result , sz)
1488
+ for i in 0 .. sz- 1 : result [i] = a[i]
1477
1489
else :
1478
1490
proc `@` * [T](a: openArray [T]) : seq [T] =
1479
1491
# # Turns an *openArray* into a sequence.
@@ -1644,8 +1656,6 @@ when not defined(js) and defined(nimV2):
1644
1656
vTable: UncheckedArray[pointer ] # vtable for types
1645
1657
PNimTypeV2 = ptr TNimTypeV2
1646
1658
1647
- proc supportsCopyMem(t: typedesc ): bool {.magic: " TypeTrait" .}
1648
-
1649
1659
when notJSnotNims and defined(nimSeqsV2):
1650
1660
include " system/strs_v2"
1651
1661
include " system/seqs_v2"
You can’t perform that action at this time.
0 commit comments