Comparing version
@@ -15,7 +15,4 @@ { | ||
"./transform" | ||
], | ||
"bindings": "esm", | ||
"exportStart": "_start" | ||
}, | ||
"extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json" | ||
] | ||
} | ||
} |
import { JSON } from ".."; | ||
import { backSlashCode, quoteCode } from "../src/chars"; | ||
import { atoi_fast, unsafeCharCodeAt } from "../src/util"; | ||
import { parseJSONInt, unsafeCharCodeAt } from "../src/util"; | ||
import { HASH } from "util/hash"; | ||
@@ -27,7 +27,7 @@ | ||
if (unsafeCharCodeAt(key, 0) == 120) { | ||
to.x = atoi_fast<i32>(data.substring(last, pos - 1)) | ||
to.x = parseJSONInt<i32>(data.substring(last, pos - 1)) | ||
} else if (unsafeCharCodeAt(key, 0) == 121) { | ||
to.y = atoi_fast<i32>(data.substring(last, pos - 1)) | ||
to.y = parseJSONInt<i32>(data.substring(last, pos - 1)) | ||
} else if (unsafeCharCodeAt(key, 0) == 122) { | ||
to.z = atoi_fast<i32>(data.substring(last, pos - 1)) | ||
to.z = parseJSONInt<i32>(data.substring(last, pos - 1)) | ||
} | ||
@@ -45,7 +45,7 @@ } | ||
if (unsafeCharCodeAt(key, 0) == 120) { | ||
to.x = atoi_fast<i32>(data.substring(last, pos - 1)) | ||
to.x = parseJSONInt<i32>(data.substring(last, pos - 1)) | ||
} else if (unsafeCharCodeAt(key, 0) == 121) { | ||
to.y = atoi_fast<i32>(data.substring(last, pos - 1)) | ||
to.y = parseJSONInt<i32>(data.substring(last, pos - 1)) | ||
} else if (unsafeCharCodeAt(key, 0) == 122) { | ||
to.z = atoi_fast<i32>(data.substring(last, pos - 1)) | ||
to.z = parseJSONInt<i32>(data.substring(last, pos - 1)) | ||
} | ||
@@ -52,0 +52,0 @@ } |
@@ -26,3 +26,3 @@ import { u128, u128Safe, u256, u256Safe, i128, i128Safe } from "as-bignum/assembly"; | ||
} from "./chars"; | ||
import { atoi_fast, escapeChar, isBigNum, unsafeCharCodeAt } from "./util"; | ||
import { parseJSONInt, escapeChar, isBigNum, unsafeCharCodeAt } from "./util"; | ||
@@ -388,3 +388,3 @@ /** | ||
// @ts-ignore | ||
return atoi_fast<T>(data); | ||
return parseJSONInt<T>(data); | ||
} | ||
@@ -391,0 +391,0 @@ // @ts-ignore |
import { StringSink } from "as-string-sink/assembly"; | ||
import { CharCode, isSpace } from "util/string"; | ||
import { backSlashCode, quoteCode } from "./chars"; | ||
import { backSlashCode, quoteCode, rCode } from "./chars"; | ||
import { u128, u128Safe, u256, u256Safe, i128, i128Safe, i256Safe } from "as-bignum/assembly"; | ||
@@ -88,8 +88,8 @@ | ||
@inline | ||
export function atoi_fast<T extends number>(str: string): T { | ||
export function atoi_fast<T extends number>(str: string, offset: i32 = 0): T { | ||
// @ts-ignore | ||
let val: T = 0; | ||
for (let pos = 0; pos < (str.length << 1); pos += 2) { | ||
for (; offset < (str.length << 1); offset += 2) { | ||
// @ts-ignore | ||
val = (val << 1) + (val << 3) + (load<u16>(changetype<usize>(str) + <usize>pos) - 48); | ||
val = (val << 1) + (val << 3) + (load<u16>(changetype<usize>(str) + <usize>offset) - 48); | ||
// We use load because in this case, there is no need to have bounds-checking | ||
@@ -101,3 +101,60 @@ } | ||
/** | ||
* | ||
*/ | ||
* Implementation of ATOI. Can be much much faster with SIMD. | ||
* Its pretty fast. (173m ops (atoi_fast) vs 89 ops (parseInt)) | ||
*/ | ||
@unsafe | ||
@inline | ||
export function parseJSONInt<T extends number>(str: string): T { | ||
// @ts-ignore | ||
let val: T = 0; | ||
let char: u16 = load<u16>(changetype<usize>(str)); | ||
let pos = 2; | ||
let neg = char === 45; | ||
// @ts-ignore | ||
val = (val << 1) + (val << 3) + (char - 48); | ||
for (; pos < (str.length << 1); pos += 2) { | ||
char = load<u16>(changetype<usize>(str) + <usize>pos); | ||
if (char === 101 || char === 69) { | ||
char = load<u16>(changetype<usize>(str) + <usize>(pos += 2)); | ||
if (char === 45) { | ||
// @ts-ignore | ||
val /= sciNote<T>(atoi_fast<T>(str, pos += 2)); | ||
if (neg === true) { | ||
// @ts-ignore | ||
return ~val + 1; | ||
} | ||
return val; | ||
} else { | ||
// @ts-ignore | ||
val *= sciNote<T>(atoi_fast<T>(str, pos += 2)); | ||
if (neg === true) { | ||
// @ts-ignore | ||
return ~val + 1; | ||
} | ||
return val; | ||
} | ||
} | ||
// @ts-ignore | ||
val = (val << 1) + (val << 3) + (char - 48); | ||
} | ||
if (neg === true) { | ||
// @ts-ignore | ||
val = ~val + 1; | ||
} | ||
return val; | ||
} | ||
function sciNote<T extends number>(num: T): T { | ||
let res = 1; | ||
if (num > 0) { | ||
for (let i = 0; i < num; i++) { | ||
res *= 10; | ||
} | ||
} else { | ||
for (let i = 0; i < num; i++) { | ||
res /= 10; | ||
} | ||
} | ||
// @ts-ignore | ||
return res; | ||
} |
import { backSlashCode, quoteCode } from "./src/chars"; | ||
import { JSON } from "./src/json"; | ||
import { atoi_fast, unsafeCharCodeAt } from "./src/util"; | ||
import { atoi_fast, parseJSONInt, unsafeCharCodeAt } from "./src/util"; | ||
@@ -54,2 +54,8 @@ @json | ||
console.log(`strtol("429496729"): ${i32.parse("429496729")}`); | ||
console.log(`strtol("429496729"): ${i32.parse("429496729")}`); | ||
console.log(parseJSONInt<i32>("321").toString()); | ||
console.log(parseJSONInt<i32>("321e1").toString()); | ||
console.log(parseJSONInt<i32>("321e2").toString()); | ||
console.log(parseJSONInt<i32>("321e3").toString()); | ||
console.log(parseJSONInt<i32>("321e-1").toString()); |
{ | ||
"name": "json-as", | ||
"version": "0.5.35", | ||
"version": "0.5.36", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -9,4 +9,6 @@ "types": "assembly/index.ts", | ||
"DogWhich", | ||
"Joshua Tenner", | ||
"Rom" | ||
"Romdotdog", | ||
"Derek Barrera", | ||
"Frankk Taylor", | ||
"lekiano" | ||
], | ||
@@ -27,3 +29,2 @@ "license": "MIT", | ||
"@as-tral/cli": "^2.0.0", | ||
"@assemblyscript/loader": "^0.27.1", | ||
"@assemblyscript/wasi-shim": "^0.1.0", | ||
@@ -30,0 +31,0 @@ "assemblyscript": "^0.27.1", |
{ | ||
"name": "@json-as/transform", | ||
"version": "0.5.35", | ||
"version": "0.5.36", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -9,4 +9,6 @@ "main": "./lib/index.js", | ||
"DogWhich", | ||
"Joshua Tenner", | ||
"Rom" | ||
"Romdotdog", | ||
"Derek Barrera", | ||
"Frankk Taylor", | ||
"lekiano" | ||
], | ||
@@ -35,2 +37,2 @@ "license": "MIT", | ||
"exports": "./lib/index.js" | ||
} | ||
} |
@@ -64,3 +64,3 @@ import { | ||
const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent); | ||
const members = [...node.members, ...(parentSchema ? parentSchema.node.members : [])] | ||
const members = [...node.members, ...(parentSchema ? parentSchema.node.members : [])]; | ||
@@ -133,3 +133,3 @@ for (const mem of members) { | ||
} | ||
` | ||
`; | ||
@@ -169,3 +169,3 @@ const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node); | ||
} | ||
}) | ||
}); | ||
@@ -172,0 +172,0 @@ // Loop over every source |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
79824
2.15%8
-11.11%1875
3.19%2467
-12.18%1
Infinity%