-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
__DESERIALIZE should take in pointer
- Loading branch information
Showing
17 changed files
with
262 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
import { BRACKET_LEFT, BRACKET_RIGHT } from "../../../custom/chars"; | ||
import { JSON } from "../../../"; | ||
import { unsafeCharCodeAt } from "../../../custom/util"; | ||
|
||
export function deserializeArrayArray<T extends unknown[][]>(data: string): T { | ||
const result = instantiate<T>(); | ||
let lastPos = 0; | ||
let depth = 0; | ||
let i = 1; | ||
// Find start of bracket | ||
//for (; unsafeCharCodeAt(data, i) !== leftBracketCode; i++) {} | ||
//i++; | ||
for (; i < data.length - 1; i++) { | ||
const char = unsafeCharCodeAt(data, i); | ||
if (char == BRACKET_LEFT) { | ||
if (depth == 0) { | ||
lastPos = i; | ||
} | ||
// Shifting is 6% faster than incrementing | ||
depth++; | ||
} else if (char == BRACKET_RIGHT) { | ||
depth--; | ||
if (depth == 0) { | ||
i++; | ||
result.push(JSON.parse<valueof<T>>(data.slice(lastPos, i))); | ||
} | ||
export function deserializeArrayArray<T extends unknown[][]>(srcStart: usize, srcEnd: usize, dst: usize): T { | ||
const out = changetype<T>(dst); | ||
let lastIndex: usize = 0; | ||
let depth: u32 = 0; | ||
while (srcStart < srcEnd) { | ||
const code = load<u16>(srcStart); | ||
if (code == BRACKET_LEFT && depth++ == 0) { | ||
lastIndex = srcStart; | ||
} else if (code == BRACKET_RIGHT && --depth == 0) { | ||
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart)); | ||
} | ||
srcStart += 2; | ||
} | ||
return result; | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { BRACE_LEFT, BRACE_RIGHT } from "../../../custom/chars"; | ||
import { JSON } from "../../.."; | ||
import { unsafeCharCodeAt } from "../../../custom/util"; | ||
|
||
export function deserializeMapArray<T extends Map<any, any>[]>(srcStart: usize, srcEnd: usize, dst: usize): T { | ||
const out = instantiate<T>(); | ||
let lastPos: usize = 2; | ||
const out = changetype<T>(dst); | ||
let lastIndex: usize = 0; | ||
let depth: u32 = 0; | ||
while (srcStart < srcEnd) { | ||
|
||
const code = load<u16>(srcStart); | ||
if (code == BRACE_LEFT && depth++ == 0) { | ||
lastIndex = srcStart; | ||
} else if (code == BRACE_RIGHT && --depth == 0) { | ||
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart)); | ||
} | ||
srcStart += 2; | ||
} | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
import { BRACE_LEFT, BRACE_RIGHT } from "../../../custom/chars"; | ||
import { JSON } from "../../.."; | ||
import { unsafeCharCodeAt } from "../../../custom/util"; | ||
|
||
export function deserializeObjectArray<T extends unknown[]>(data: string): T { | ||
const result = instantiate<T>(); | ||
let lastPos: u32 = 1; | ||
export function deserializeObjectArray<T extends unknown[]>(srcStart: usize, srcEnd: usize, dst: usize): T { | ||
const out = changetype<T>(dst); | ||
let lastIndex: usize = 0; | ||
let depth: u32 = 0; | ||
for (let pos: u32 = 0; pos < <u32>data.length; pos++) { | ||
const char = unsafeCharCodeAt(data, pos); | ||
if (char == BRACE_LEFT) { | ||
if (depth == 0) { | ||
lastPos = pos; | ||
} | ||
depth++; | ||
} else if (char == BRACE_RIGHT) { | ||
depth--; | ||
if (depth == 0) { | ||
pos++; | ||
result.push(JSON.parse<valueof<T>>(data.slice(lastPos, pos))); | ||
//lastPos = pos + 2; | ||
} | ||
while (srcStart < srcEnd) { | ||
const code = load<u16>(srcStart); | ||
if (code == BRACE_LEFT && depth++ == 0) { | ||
lastIndex = srcStart; | ||
} else if (code == BRACE_RIGHT && --depth == 0) { | ||
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart)); | ||
} | ||
srcStart += 2; | ||
} | ||
return result; | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,11 @@ | ||
// @ts-ignore: Decorator valid here | ||
@inline export function deserializeFloat<T>(data: string): T { | ||
// @ts-ignore | ||
const type: T = 0; | ||
// @ts-ignore | ||
if (type instanceof f64) return f64.parse(data); | ||
// @ts-ignore | ||
return f32.parse(data); | ||
} | ||
import { ptrToStr } from "../../util/ptrToStr"; | ||
|
||
// @ts-ignore: Decorator valid here | ||
@inline export function deserializeFloat_NEW<T>(srcStart: usize, srcEnd: usize): T { | ||
@inline export function deserializeFloat<T>(srcStart: usize, srcEnd: usize): T { | ||
// @ts-ignore | ||
const type: T = 0; | ||
// @ts-ignore | ||
if (type instanceof f64) return f64.parse(str(srcStart, srcEnd)); | ||
if (type instanceof f64) return f64.parse(ptrToStr(srcStart, srcEnd)); | ||
// @ts-ignore | ||
return f32.parse(str(srcStart, srcEnd)); | ||
} | ||
|
||
function str(start: usize, end: usize): string { | ||
const size = end - start; | ||
const out = __new(size, idof<string>()); | ||
memory.copy(out, start, size); | ||
return changetype<string>(out); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.