Skip to content

Commit

Permalink
fix: point as-bs imports to submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jan 21, 2025
1 parent 7bf972f commit a5112ff
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 33 deletions.
19 changes: 0 additions & 19 deletions assembly/__benches__/misc.bench.ts
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
import { bench } from "as-bench/assembly/bench";
import { bs } from "as-bs";
import { deserializeString_SIMD } from "../deserialize/simd/string";
import { deserializeString } from "../deserialize/simple/string";
import { bytes } from "../util/bytes";
const str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()\\\"\t\r\f\n\u0000';
const str2 = '"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()\\\\\\"\\t\\r\\f\\n\\u0000"';
const srcStart = changetype<usize>(str);
const srcEnd = srcStart + bytes(str);
bs.ensureSize(2048);
bench("Deserialize String (Simple)", () => {
deserializeStrin(str2);
});
// bench("Deserialize String (SIMD)", () => {
// (str2, bs.buffer);
// });
bench("Deserialize String (SIMD)", () => {
deserializeString_SIMD(str2, srcStart, srcEnd, __new(158, idof<string>()));
});
2 changes: 1 addition & 1 deletion assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="./index.d.ts" />
import { bs } from "as-bs";
import { bs } from "../modules/as-bs";

import { serializeString } from "./serialize/simple/string";
import { serializeArray } from "./serialize/simple/array";
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simd/string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";
import { BACK_SLASH } from "../../custom/chars";
import { SERIALIZE_ESCAPE_TABLE } from "../../globals/tables";
import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";
import { COMMA, BRACKET_RIGHT, BRACKET_LEFT } from "../../custom/chars";
import { JSON } from "../..";

Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/bool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";

/**
* Serialize a bool to type string
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";
import { QUOTE } from "../../custom/chars";
import { bytes } from "../../util/bytes";

Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/float.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dtoa_buffered } from "util/number";
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";

export function serializeFloat<T extends number>(data: T): void {
bs.ensureSize(64);
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/integer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { itoa_buffered } from "util/number";
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";

export function serializeInteger<T extends number>(data: T): void {
bs.ensureSize(sizeof<T>() << 3);
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/map.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSON } from "../..";
import { BRACE_LEFT, BRACE_RIGHT, COLON, COMMA } from "../../custom/chars";
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";

export function serializeMap<T extends Map<any, any>>(src: T): void {
const srcSize = src.size;
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _intTo16 } from "../../custom/util";
import { bytes } from "../../util/bytes";
import { bs } from "as-bs";
import { bs } from "../../../modules/as-bs";
import { BACK_SLASH, QUOTE } from "../../custom/chars";
import { SERIALIZE_ESCAPE_TABLE } from "../../globals/tables";

Expand Down
10 changes: 8 additions & 2 deletions transform/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion transform/lib/index.js.map

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions transform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,27 @@ class JSONTransform extends Visitor {
super.visitSource(node);
}
addRequiredImports(node: ClassDeclaration): void {
// if (!this.imports.find((i) => i.declarations.find((d) => d.foreignName.text == "bs"))) {
// if (!this.bsImport) {
// this.bsImport = "import { bs } from \"as-bs\"";
// if (process.env["JSON_DEBUG"]) console.log("Added as-bs import: " + this.bsImport + "\n");
// }
// }
if (!this.imports.find((i) => i.declarations.find((d) => d.foreignName.text == "bs"))) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

let relativePath = path.relative(path.dirname(node.range.source.normalizedPath), path.resolve(__dirname, "../../modules/as-bs/"));

if (!relativePath.startsWith(".") && !relativePath.startsWith("/")) relativePath = "./" + relativePath;
// if (!existsSync(relativePath)) {
// throw new Error("Could not find a valid json-as library to import from! Please add import { JSON } from \"path-to-json-as\"; in " + node.range.source.normalizedPath + "!");
// }

const txt = `import { bs } from "${relativePath}";`;
if (!this.bsImport) {
this.bsImport = "import { bs } from \"as-bs\"";
if (process.env["JSON_DEBUG"]) console.log("Added as-bs import: " + this.bsImport + "\n");
this.bsImport = txt;
if (process.env["JSON_DEBUG"]) console.log("Added as-bs import: " + txt + "\n");
}
}

Expand Down

0 comments on commit a5112ff

Please sign in to comment.