Prefer JS typed arrays for arrays.
This commit is contained in:
parent
ac1e7a2450
commit
d148fdab5c
1 changed files with 27 additions and 4 deletions
|
|
@ -1138,6 +1138,18 @@ proc createObjInitList(p: PProc, typ: PType, excludedFieldIDs: IntSet, output: v
|
||||||
createRecordVarAux(p, t.n, excludedFieldIDs, output)
|
createRecordVarAux(p, t.n, excludedFieldIDs, output)
|
||||||
t = t.sons[0]
|
t = t.sons[0]
|
||||||
|
|
||||||
|
proc arrayTypeForElemType(typ: PType): string =
|
||||||
|
case typ.kind
|
||||||
|
of tyInt, tyInt32: "Int32Array"
|
||||||
|
of tyInt16: "Int16Array"
|
||||||
|
of tyInt8: "Int8Array"
|
||||||
|
of tyUint, tyUint32: "Uint32Array"
|
||||||
|
of tyUint16: "Uint16Array"
|
||||||
|
of tyUint8: "Uint8Array"
|
||||||
|
of tyFloat32: "Float32Array"
|
||||||
|
of tyFloat64, tyFloat: "Float64Array"
|
||||||
|
else: nil
|
||||||
|
|
||||||
proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||||
var t = skipTypes(typ, abstractInst)
|
var t = skipTypes(typ, abstractInst)
|
||||||
case t.kind
|
case t.kind
|
||||||
|
|
@ -1152,9 +1164,12 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||||
of tyBool:
|
of tyBool:
|
||||||
result = putToSeq("false", indirect)
|
result = putToSeq("false", indirect)
|
||||||
of tyArray, tyArrayConstr:
|
of tyArray, tyArrayConstr:
|
||||||
var length = int(lengthOrd(t))
|
let length = int(lengthOrd(t))
|
||||||
var e = elemType(t)
|
let e = elemType(t)
|
||||||
if length > 32:
|
let jsTyp = arrayTypeForElemType(e)
|
||||||
|
if not jsTyp.isNil:
|
||||||
|
result = "new $1($2)" % [rope(jsTyp), rope(length)]
|
||||||
|
elif length > 32:
|
||||||
useMagic(p, "arrayConstr")
|
useMagic(p, "arrayConstr")
|
||||||
# XXX: arrayConstr depends on nimCopy. This line shouldn't be necessary.
|
# XXX: arrayConstr depends on nimCopy. This line shouldn't be necessary.
|
||||||
useMagic(p, "nimCopy")
|
useMagic(p, "nimCopy")
|
||||||
|
|
@ -1766,7 +1781,15 @@ proc genHeader(): Rope =
|
||||||
"/* (c) 2015 Andreas Rumpf */$n$n" &
|
"/* (c) 2015 Andreas Rumpf */$n$n" &
|
||||||
"var framePtr = null;$n" &
|
"var framePtr = null;$n" &
|
||||||
"var excHandler = 0;$n" &
|
"var excHandler = 0;$n" &
|
||||||
"var lastJSError = null;$n") %
|
"var lastJSError = null;$n" &
|
||||||
|
"if (typeof Int8Array === 'undefined') Int8Array = Array;$n" &
|
||||||
|
"if (typeof Int16Array === 'undefined') Int16Array = Array;$n" &
|
||||||
|
"if (typeof Int32Array === 'undefined') Int32Array = Array;$n" &
|
||||||
|
"if (typeof Uint8Array === 'undefined') Uint8Array = Array;$n" &
|
||||||
|
"if (typeof Uint16Array === 'undefined') Uint16Array = Array;$n" &
|
||||||
|
"if (typeof Uint32Array === 'undefined') Uint32Array = Array;$n" &
|
||||||
|
"if (typeof Float32Array === 'undefined') Float32Array = Array;$n" &
|
||||||
|
"if (typeof Float64Array === 'undefined') Float64Array = Array;$n") %
|
||||||
[rope(VersionAsString)]
|
[rope(VersionAsString)]
|
||||||
|
|
||||||
proc genModule(p: PProc, n: PNode) =
|
proc genModule(p: PProc, n: PNode) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue