fix(compiler): move projection attributes into constants · angular/angular@ae1c8a1 · GitHub
Skip to content

Commit ae1c8a1

Browse files
crisbetopkozlowski-opensource
authored andcommitted
fix(compiler): move projection attributes into constants
We can save some memory by moving the `attrs` passed into the `projection` instruction into the constant pool. (cherry picked from commit f0b28f6)
1 parent 9f6fda6 commit ae1c8a1

6 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/content_projection/ng_content_fallback.js‎

Lines changed: 2 additions & 1 deletion

‎packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/content_projection/project_as_ng_content.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11

2-
const _c0 = [[["", "card-title", ""]], [["", "card-content", ""]]];
3-
const _c1 = ["[card-title]", "[card-content]"];
4-
const _c2 = ["*"];
2+
const $_c0$ = [[["", "card-title", ""]], [["", "card-content", ""]]];
3+
const $_c1$ = ["[card-title]", "[card-content]"];
4+
const $_c2$ = ["*"];
5+
const $_c3$ = ["ngProjectAs", "[card-content]", 5, ["", "card-content", ""]];
56
// ...
67
selectors: [["card"]],
78
standalone: false,
8-
ngContentSelectors: _c1,
9+
ngContentSelectors: $_c1$,
910
decls: 3,
1011
vars: 0,
1112
template: function Card_Template(rf, ctx) {
1213
if (rf & 1) {
13-
i0.ɵɵprojectionDef(_c0);
14+
i0.ɵɵprojectionDef($_c0$);
1415
i0.ɵɵprojection(0);
1516
i0.ɵɵtext(1, " --- ");
1617
i0.ɵɵprojection(2, 1);
@@ -19,7 +20,7 @@ template: function Card_Template(rf, ctx) {
1920
// ...
2021
selectors: [["card-with-title"]],
2122
standalone: false,
22-
ngContentSelectors: _c2,
23+
ngContentSelectors: $_c2$,
2324
decls: 4,
2425
vars: 0,
2526
consts: [["ngProjectAs", "[card-title]", 5, ["", "card-title", ""]]],
@@ -29,7 +30,7 @@ template: function CardWithTitle_Template(rf, ctx) {
2930
i0.ɵɵelementStart(0, "card")(1, "h1", 0);
3031
i0.ɵɵtext(2, "Title");
3132
i0.ɵɵelementEnd();
32-
i0.ɵɵprojection(3, 0, ["ngProjectAs", "[card-content]", 5, ["", "card-content", ""]]);
33+
i0.ɵɵprojection(3, 0, $_c3$);
3334
i0.ɵɵelementEnd();
3435
}
3536
}
@@ -44,4 +45,4 @@ template: function App_Template(rf, ctx) {
4445
i0.ɵɵtext(1, "content");
4546
i0.ɵɵelementEnd();
4647
}
47-
}
48+
}

‎packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_template/self_closing_structural_directives.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const $_c1$ = ["*ngIf", "flag"];
2+
13
function MyComponent_img_2_Template(rf, ctx) {
24
if (rf & 1) {
35
i0.ɵɵi18nStart(0, 0, 1);
@@ -34,7 +36,7 @@ function MyComponent_ng_container_5_Template(rf, ctx) {
3436
function MyComponent_ng_content_6_Template(rf, ctx) {
3537
if (rf & 1) {
3638
i0.ɵɵi18nStart(0, 0, 6);
37-
i0.ɵɵprojection(1, 0, ["*ngIf", "flag"]);
39+
i0.ɵɵprojection(1, 0, $_c1$);
3840
i0.ɵɵi18nEnd();
3941
}
4042
}

‎packages/compiler/src/template/pipeline/ir/src/ops/create.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ export interface ProjectionOp extends Op<CreateOp>, ConsumesSlotOpTrait {
11371137

11381138
projectionSlotIndex: number;
11391139

1140-
attributes: null | o.LiteralArrayExpr;
1140+
attributes: null | o.Expression;
11411141

11421142
localRefs: string[];
11431143

‎packages/compiler/src/template/pipeline/src/instruction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export function projectionDef(def: o.Expression | null): ir.CreateOp {
393393
export function projection(
394394
slot: number,
395395
projectionSlotIndex: number,
396-
attributes: o.LiteralArrayExpr | null,
396+
attributes: o.Expression | null,
397397
fallbackFnName: string | null,
398398
fallbackDecls: number | null,
399399
fallbackVars: number | null,

‎packages/compiler/src/template/pipeline/src/phases/const_collection.ts‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)