Skip to content

Commit

Permalink
suggestion to respect typedarray type (#19257)
Browse files Browse the repository at this point in the history
* suggestion to respect typedarray

* Update jssys.nim

Co-authored-by: Sven Keller <s.keller@cortona.de>
  • Loading branch information
NevsDev and NevsDev committed Dec 16, 2021
1 parent c17baae commit 5d2bab7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/system/jssys.nim
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,33 @@ proc nimCopy(dest, src: JSRef, ti: PNimType): JSRef =
else:
asm "`result` = (`dest` === null || `dest` === undefined) ? {} : `dest`;"
nimCopyAux(result, src, ti.node)
of tySequence, tyArrayConstr, tyOpenArray, tyArray:
of tyArrayConstr, tyArray:
# In order to prevent a type change (TypedArray -> Array) and to have better copying performance,
# arrays constructors are considered separately
asm """
if(ArrayBuffer.isView(`src`)) {
if(`dest` === null || `dest` === undefined || `dest`.length != `src`.length) {
`dest` = new `src`.constructor(`src`);
} else {
`dest`.set(`src`, 0);
}
`result` = `dest`;
} else {
if (`src` === null) {
`result` = null;
}
else {
if (`dest` === null || `dest` === undefined || `dest`.length != `src`.length) {
`dest` = new Array(`src`.length);
}
`result` = `dest`;
for (var i = 0; i < `src`.length; ++i) {
`result`[i] = nimCopy(`result`[i], `src`[i], `ti`.base);
}
}
}
"""
of tySequence, tyOpenArray:
asm """
if (`src` === null) {
`result` = null;
Expand Down

0 comments on commit 5d2bab7

Please sign in to comment.