Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6cfd8b3

Browse files
HerrCai0907MaxGraey
andauthoredAug 15, 2022
Template literal optimization (#2432)
Co-authored-by: Max Graey <maxgraey@gmail.com>
1 parent fd90fda commit 6cfd8b3

File tree

5 files changed

+484
-482
lines changed

5 files changed

+484
-482
lines changed
 

‎src/compiler.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -8111,12 +8111,13 @@ export class Compiler extends DiagnosticEmitter {
81118111
}
81128112

81138113
// Compile to a `StaticArray<string>#join("") in the general case
8114-
let length = numParts + numExpressions;
8115-
let values = new Array<usize>(length);
8116-
values[0] = this.ensureStaticString(parts[0]);
8114+
let expressionPositions = new Array<i32>(numExpressions);
8115+
let values = new Array<usize>();
8116+
if (parts[0].length > 0) values.push(this.ensureStaticString(parts[0]));
81178117
for (let i = 1; i < numParts; ++i) {
8118-
values[2 * i - 1] = module.usize(0);
8119-
values[2 * i] = this.ensureStaticString(parts[i]);
8118+
expressionPositions[i - 1] = values.length;
8119+
values.push(module.usize(0));
8120+
if (parts[i].length > 0) values.push(this.ensureStaticString(parts[i]));
81208121
}
81218122
let arrayInstance = assert(this.resolver.resolveClass(this.program.staticArrayPrototype, [ stringType ]));
81228123
let segment = this.addStaticBuffer(stringType, values, arrayInstance.id);
@@ -8145,7 +8146,7 @@ export class Compiler extends DiagnosticEmitter {
81458146
for (let i = 0; i < numExpressions; ++i) {
81468147
stmts[numExpressions + i] = this.makeCallDirect(indexedSetInstance, [
81478148
module.usize(offset),
8148-
module.i32(2 * i + 1),
8149+
module.i32(expressionPositions[i]),
81498150
module.local_get(temps[i].index, stringType.toRef())
81508151
], expression);
81518152
flow.freeTempLocal(temps[i]);
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.