Skip to content

Commit

Permalink
remove inline decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jan 17, 2025
1 parent f023966 commit 5111abd
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 44 deletions.
3 changes: 1 addition & 2 deletions assembly/deserialize/simd/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const SPLAT_92 = i16x8.splat(92); /* \ */
* @returns number of bytes written
*/
// todo: optimize and stuff. it works, its not pretty. ideally, i'd like this to be (nearly) branchless
// @ts-ignore: Decorator
@inline export function deserializeString_SIMD(src: string, srcStart: usize, srcEnd: usize, dst: usize): usize {
export function deserializeString_SIMD(src: string, srcStart: usize, srcEnd: usize, dst: usize): usize {
let src_ptr = srcStart + 2;
let dst_ptr = changetype<usize>(dst);

Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { deserializeFloat } from "./float";
import { deserializeObject } from "./object";
import { deserializeString } from "./string";

// @ts-ignore
@inline export function deserializeArbitrary(srcStart: usize, srcEnd: usize, dst: usize): JSON.Value {
export function deserializeArbitrary(srcStart: usize, srcEnd: usize, dst: usize): JSON.Value {
const firstChar = load<u16>(srcStart);
if (firstChar == 34) return JSON.Value.from(deserializeString(srcStart, srcEnd, dst));
else if (firstChar == 123) return JSON.Value.from(deserializeObject(srcStart, srcEnd, dst));
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/array/bool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CHAR_E, CHAR_F, CHAR_T } from "../../../custom/chars";

// @ts-ignore: Decorator valid here
@inline export function deserializeBooleanArray<T extends boolean[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
export function deserializeBooleanArray<T extends boolean[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
const out = changetype<T>(dst);
while (srcStart < srcEnd) {
const code = load<u16>(srcStart);
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/array/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { isSpace } from "../../../util";
import { COMMA, BRACE_RIGHT } from "../../../custom/chars";
import { JSON } from "../../..";

// @ts-ignore: Decorator valid here
@inline export function deserializeFloatArray<T extends number[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
export function deserializeFloatArray<T extends number[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
const out = changetype<T>(dst);
let lastIndex: usize = 0;
while (srcStart < srcEnd) {
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/array/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { isSpace } from "../../../util";
import { COMMA, BRACE_RIGHT } from "../../../custom/chars";
import { JSON } from "../../..";

// @ts-ignore: Decorator valid here
@inline export function deserializeIntegerArray<T extends number[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
export function deserializeIntegerArray<T extends number[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
const out = changetype<T>(dst);
let lastIndex: usize = 0;
while (srcStart < srcEnd) {
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/array/string.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { JSON } from "../../..";
import { BACK_SLASH, QUOTE } from "../../../custom/chars";

// @ts-ignore: Decorator valid here
@inline export function deserializeStringArray(srcStart: usize, srcEnd: usize, dst: usize): string[] {
export function deserializeStringArray(srcStart: usize, srcEnd: usize, dst: usize): string[] {
const out = changetype<string[]>(dst);
let lastPos = 2;
let inString = false;
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/bool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CHAR_F, CHAR_T } from "../../custom/chars";

// @ts-ignore: Decorator valid here
@inline export function deserializeBoolean(srcStart: usize, srcEnd: usize): boolean {
export function deserializeBoolean(srcStart: usize, srcEnd: usize): boolean {
const srcSize = srcEnd - srcStart;
const firstChar = load<u16>(srcStart);
if (srcSize == 4 && firstChar == CHAR_T && load<u64>(srcStart) == 28429475166421108) return true;
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/date.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ptrToStr } from "../../util/ptrToStr";

// @ts-ignore: Decorator valid here
@inline export function deserializeDate(srcStart: usize, srcEnd: usize): Date {
export function deserializeDate(srcStart: usize, srcEnd: usize): Date {
// Use AssemblyScript's date parser
const d = Date.fromString(ptrToStr(srcStart, srcEnd));

Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/float.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ptrToStr } from "../../util/ptrToStr";

// @ts-ignore: Decorator valid here
@inline export function deserializeFloat<T>(srcStart: usize, srcEnd: usize): T {
export function deserializeFloat<T>(srcStart: usize, srcEnd: usize): T {
// @ts-ignore
const type: T = 0;
// @ts-ignore
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/integer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { atoi } from "../../util/atoi";

// @ts-ignore: Decorator valid here
@inline export function deserializeInteger<T>(srcStart: usize, srcEnd: usize): T {
export function deserializeInteger<T>(srcStart: usize, srcEnd: usize): T {
return atoi<T>(srcStart, srcEnd);
}
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
return out;
}

// @ts-ignore: Decorator valid here
@inline function sliceTo(srcStart: usize, srcEnd: usize): string {
function sliceTo(srcStart: usize, srcEnd: usize): string {
const dstSize = srcEnd - srcStart;
const dst = __new(dstSize, idof<string>());
memory.copy(dst, srcStart, dstSize);
Expand Down
3 changes: 1 addition & 2 deletions assembly/deserialize/simple/string.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BACK_SLASH } from "../../custom/chars";
import { DESERIALIZE_ESCAPE_TABLE, ESCAPE_HEX_TABLE } from "../../globals/tables";

// @ts-ignore: Decorator valid here
@inline export function deserializeString(srcStart: usize, srcEnd: usize, dst: usize): string {
export function deserializeString(srcStart: usize, srcEnd: usize, dst: usize): string {
let dstPtr = dst;
let lastPtr = srcStart;
while (srcStart < srcEnd) {
Expand Down
16 changes: 9 additions & 7 deletions assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,20 @@ export namespace JSON {
* @returns T
*/
export function parse<T>(data: string): T {
const dataSize = bytes(data);
const dataPtr = changetype<usize>(data);
if (isBoolean<T>()) {
return deserializeBoolean(data) as T;
return deserializeBoolean(dataPtr, dataPtr + dataSize) as T;
} else if (isInteger<T>()) {
return deserializeInteger<T>(data);
return deserializeInteger<T>(dataPtr, dataPtr + dataSize);
} else if (isFloat<T>()) {
return deserializeFloat<T>(data);
return deserializeFloat<T>(dataPtr, dataPtr + dataSize);
} else if (isNullable<T>() && data.length == 4 && data == "null") {
// @ts-ignore
return null;
} else if (isString<T>()) {
// @ts-ignore
return deserializeString(data);
return deserializeString(dataPtr, dataPtr + dataSize);
} else if (isArray<T>()) {
// @ts-ignore
return deserializeArray<nonnull<T>>(data);
Expand All @@ -172,13 +174,13 @@ export namespace JSON {
// @ts-ignore: Defined by transform
if (isDefined(type.__DESERIALIZE)) {
// @ts-ignore
return deserializeObject<nonnull<T>>(data.trimStart());
return deserializeObject<nonnull<T>>(dataPtr, dataPtr + dataSize);
} else if (type instanceof Map) {
// @ts-ignore
return deserializeMap<nonnull<T>>(data.trimStart());
return deserializeMap<nonnull<T>>(dataPtr, dataPtr + dataSize);
} else if (type instanceof Date) {
// @ts-ignore
return deserializeDate(data);
return deserializeDate(dataPtr, dataPtr + dataSize);
} else {
ERROR(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
}
Expand Down
3 changes: 1 addition & 2 deletions assembly/serialize/simd/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const SPLAT_0 = i16x8.splat(0); /* 0 */
* @param srcStart pointer to begin serializing at
* @param srcEnd pointer to end serialization at
*/
// @ts-ignore: Decorator valid here
@inline export function serializeString_SIMD(src: string): void {
export function serializeString_SIMD(src: string): void {
const srcSize = changetype<OBJECT>(changetype<usize>(src) - TOTAL_OVERHEAD).rtSize;
let srcStart = changetype<usize>(src);
const srcEnd = srcStart + srcSize;
Expand Down
3 changes: 1 addition & 2 deletions assembly/serialize/simple/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { bs } from "as-bs";
* @param data data to serialize
* @returns void
*/
// @ts-ignore: Decorator valid here
@inline export function serializeBool(data: bool, staticSize: bool = false): void {
export function serializeBool(data: bool, staticSize: bool = false): void {
if (data == true) {
if (!staticSize) bs.ensureSize(8);
store<u64>(bs.offset, 28429475166421108);
Expand Down
3 changes: 1 addition & 2 deletions assembly/serialize/simple/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { bs } from "as-bs";
import { QUOTE } from "../../custom/chars";
import { bytes } from "../../util/bytes";

// @ts-ignore: Decorator valid here
@inline export function serializeDate(src: Date, staticSize: bool = false): void {
export function serializeDate(src: Date, staticSize: bool = false): void {
const data = src.toISOString();
const dataSize = bytes(data);
if (!staticSize) bs.ensureSize(dataSize + 4);
Expand Down
3 changes: 1 addition & 2 deletions assembly/serialize/simple/float.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { dtoa_buffered } from "util/number";
import { bs } from "as-bs";

// @ts-ignore: Decorator valid here
@inline export function serializeFloat<T extends number>(data: T, staticSize: bool = false): void {
export function serializeFloat<T extends number>(data: T, staticSize: bool = false): void {
if (!staticSize) bs.ensureSize(64);
bs.offset += dtoa_buffered(bs.offset, data) << 1;
}
5 changes: 2 additions & 3 deletions assembly/serialize/simple/integer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { itoa_buffered } from "util/number";
import { bs } from "as-bs";

// @ts-ignore: Decorator valid here
@inline export function serializeInteger<T extends number>(data: T, staticSize: bool = false): void {
if (!staticSize) bs.ensureSize(sizeof<T>() << 3);
export function serializeInteger<T extends number>(data: T): void {
// bs.ensureSize(sizeof<T>() << 3);
bs.offset += itoa_buffered(bs.offset, data) << 1;
}
3 changes: 1 addition & 2 deletions assembly/serialize/simple/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { SERIALIZE_ESCAPE_TABLE } from "../../globals/tables";
* @param src string
* @returns void
*/
// @ts-ignore: Decorator
@inline export function serializeString(src: string): void {
export function serializeString(src: string): void {
const srcSize = bytes(src);
bs.ensureSize(srcSize + 4);
let srcPtr = changetype<usize>(src);
Expand Down

0 comments on commit 5111abd

Please sign in to comment.