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 @@ -1465,15 +1465,26 @@ 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
+ result = newSeqUninit[T](sz)
1480
+ when nimvm :
1481
+ for i in 0..sz-1: result [i] = a[i]
1482
+ else:
1483
+ if sz != 0:
1484
+ copyMem(addr result [ 0], addr a[0 ], sizeof(T) * sz)
1485
+ else :
1486
+ newSeq(result , sz)
1487
+ for i in 0 .. sz- 1 : result [i] = a[i]
1477
1488
else :
1478
1489
proc `@` * [T](a: openArray [T]) : seq [T] =
1479
1490
# # Turns an *openArray* into a sequence.
@@ -1644,8 +1655,6 @@ when not defined(js) and defined(nimV2):
1644
1655
vTable: UncheckedArray[pointer ] # vtable for types
1645
1656
PNimTypeV2 = ptr TNimTypeV2
1646
1657
1647
- proc supportsCopyMem(t: typedesc ): bool {.magic: " TypeTrait" .}
1648
-
1649
1658
when notJSnotNims and defined(nimSeqsV2):
1650
1659
include " system/strs_v2"
1651
1660
include " system/seqs_v2"
You can’t perform that action at this time.
0 commit comments