Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jun 11, 2024
1 parent 53c444f commit 07af06a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions assembly/deserialize/array/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { deserializeNumber } from "../number";
if (lastPos === 0 && ((char >= 48 && char <= 57) || char === 45)) {
lastPos = i;
} else if ((isSpace(char) || char == commaCode) && lastPos > 0) {
console.log("result: " + data.slice(lastPos, i));
result.push(deserializeNumber<valueof<T>>(data, lastPos, i));
lastPos = 0;
}
Expand All @@ -21,6 +22,7 @@ import { deserializeNumber } from "../number";
const char = unsafeCharCodeAt(data, i);
if (char !== rightBracketCode) {
result.push(deserializeNumber<valueof<T>>(data, lastPos, i + 1));
console.log("result: " + data.slice(lastPos, i + 1));
break;
}
}
Expand Down
8 changes: 6 additions & 2 deletions assembly/deserialize/number.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { snip_fast } from "../src/util";
import { __atoi_fast, snip_fast } from "../src/util";


// @ts-ignore: Decorator
@inline export function deserializeNumber<T>(data: string, start: i32 = 0, end: i32 = 0): T {
if (isInteger<T>()) {
// @ts-ignore
return snip_fast<T>(data, start, end || data.length << 1);
return __atoi_fast<T>(
data,
start << 1,
end << 1 || data.length << 1
);
}
// @ts-ignore
const type: T = 0;
Expand Down
6 changes: 3 additions & 3 deletions assembly/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ describe("Serialize Maps", () => {
});

describe("Deserialize Number", () => {
expect(JSON.serialize(deserializeNumber<i32>("1234e3")).toString()).toBe("1234000");
expect(JSON.serialize(deserializeNumber<i32>("1234")).toString()).toBe("1234");
})
/*


describe("Deserialize String[]", () => {
expect(JSON.serialize(deserializeStringArray("[\"hello\",\"world\"]")).toString()).toBe("[\"hello\",\"world\"]");
Expand All @@ -147,7 +147,7 @@ describe("Deserialize Number[]", () => {
describe("Deserialize Boolean[]", () => {
expect(JSON.serialize(deserializeBooleanArray<bool[]>("[true, false]")).toString()).toBe("[true,false]");
});
/*
describe("Deserialize [][]", () => {
deserializeArray<JSON.Value[]>("[[[]],[[[]]]]")
});*/
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"microtime": "^3.1.1",
"prettier": "^3.1.1",
"tinybench": "^2.8.0",
"typescript": "^5.3.3",
"visitor-as": "^0.11.4"
"typescript": "^5.3.3"
},
"dependencies": {
"as-container": "^0.8.0",
"as-string-sink": "^0.5.3",
"as-variant": "^0.4.1",
"as-virtual": "^0.1.9"
"as-virtual": "^0.1.9",
"json-as": "^0.8.4"
},
"overrides": {
"assemblyscript": "$assemblyscript"
Expand Down

0 comments on commit 07af06a

Please sign in to comment.