Skip to content

Commit 88c29e8

Browse files
committed
Use array instead of map
1 parent d39a435 commit 88c29e8

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

bench/decode.bench.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { decode, DecodeMode } from "../mod.ts";
99

1010
const BENCHMARKS = await (async () => {
1111
const result = [];
12-
for await (const file of expandGlob("*.js.map", { root: import.meta.dirname })) {
12+
for await (
13+
const file of expandGlob("*.js.map", { root: import.meta.dirname })
14+
) {
1315
const mapContent = Deno.readTextFileSync(file.path);
1416
const mapJson = JSON.parse(mapContent);
1517
result.push({
@@ -21,7 +23,7 @@ const BENCHMARKS = await (async () => {
2123
return result;
2224
})();
2325

24-
for (const {name, mapJson, size} of BENCHMARKS) {
26+
for (const { name, mapJson, size } of BENCHMARKS) {
2527
Deno.bench(`${name}, lax, ${format(size)}`, () => {
2628
decode(mapJson, { mode: DecodeMode.LOOSE });
2729
});

deno.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/decode/decode.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ class Decoder {
7676
readonly #scopeStack: OriginalScope[] = [];
7777
readonly #rangeStack: GeneratedRange[] = [];
7878

79-
readonly #countToScope = new Map<number, OriginalScope>();
80-
#scopeCounter = 0;
79+
#flatOriginalScopes: OriginalScope[] = [];
8180

8281
constructor(scopes: string, names: string[], options?: { mode: DecodeMode }) {
8382
this.#encodedScopes = scopes;
@@ -117,7 +116,7 @@ class Decoder {
117116
);
118117

119118
this.#scopeStack.push(scope);
120-
this.#countToScope.set(this.#scopeCounter++, scope);
119+
this.#flatOriginalScopes.push(scope);
121120
break;
122121
}
123122
case Tag.ORIGINAL_SCOPE_VARIABLES: {
@@ -187,9 +186,8 @@ class Decoder {
187186

188187
if (item.definitionIdx !== undefined) {
189188
this.#rangeState.defScopeIdx += item.definitionIdx;
190-
range.originalScope = this.#countToScope.get(
191-
this.#rangeState.defScopeIdx,
192-
);
189+
range.originalScope =
190+
this.#flatOriginalScopes[this.#rangeState.defScopeIdx];
193191
// TODO: Maybe throw if the idx is invalid?
194192
}
195193

@@ -265,8 +263,7 @@ class Decoder {
265263

266264
this.#scopes = [];
267265
this.#ranges = [];
268-
this.#scopeCounter = 0;
269-
this.#countToScope.clear();
266+
this.#flatOriginalScopes = [];
270267

271268
return info;
272269
}

0 commit comments

Comments
 (0)