@samitouri / QOS-React-2 / commits / f54d121d71

[hir][be] Use a Map to store JsxExpression.props

Semantically this seems like a better fit as we're using Map like methods to iterate and update values anyway.

Sathya Gunasekaran committed Oct 24, 2022 at 16:04 UTC f54d121d7171debcabe0cb60b55750a808ae3a32
5 files changed +6 -6
compiler/forget/src/HIR/BuildHIR.ts
+2 -2
@@ -860,7 +860,7 @@ function lowerExpression(
860 const children = expr
861 .get("children")
862 .map((child) => lowerJsxElement(builder, child));
863 - const props: { [prop: string]: Place } = {};
863 + const props: Map<string, Place> = new Map();
864 opening.get("attributes").forEach((attribute) => {
865 todoInvariant(attribute.isJSXAttribute(), "handle spread attributes");
866 const name = attribute.get("name");
@@ -882,7 +882,7 @@ function lowerExpression(
882 value = lowerExpressionToPlace(builder, expression);
883 }
884 const prop: string = name.node.name;
885 - props[prop] = value;
885 + props.set(prop, value);
886 });
887 return {
888 kind: "JsxExpression",
compiler/forget/src/HIR/Codegen.ts
+1 -1
@@ -215,7 +215,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array<t.Statement>) {
215 }
216 case "JsxExpression": {
217 const attributes: Array<t.JSXAttribute> = [];
218 - for (const [prop, value] of Object.entries(instrValue.props)) {
218 + for (const [prop, value] of instrValue.props) {
219 attributes.push(
220 t.jsxAttribute(
221 t.jsxIdentifier(prop),
compiler/forget/src/HIR/HIR.ts
+1 -1
@@ -185,7 +185,7 @@ export type InstructionData =
185 | {
186 kind: "JsxExpression";
187 tag: Place;
188 - props: { [prop: string]: Place };
188 + props: Map<string, Place>;
189 children: Array<Place> | null; // null === no children
190 }
191 | {
compiler/forget/src/HIR/InferReferenceEffects.ts
+1 -1
@@ -546,7 +546,7 @@ function inferBlock(env: Environment, block: BasicBlock) {
546 case "JsxExpression": {
547 valueKind = ValueKind.Frozen;
548 env.reference(instrValue.tag, Effect.Freeze);
549 - for (const [_prop, value] of Object.entries(instrValue.props)) {
549 + for (const [_prop, value] of instrValue.props) {
550 env.reference(value, Effect.Freeze);
551 }
552 if (instrValue.children !== null) {
compiler/forget/src/HIR/PrintHIR.ts
+1 -1
@@ -191,7 +191,7 @@ function printInstructionValue(instrValue: InstructionValue): string {
191 }
192 case "JsxExpression": {
193 const propItems = [];
194 - for (const [prop, value] of Object.entries(instrValue.props)) {
194 + for (const [prop, value] of instrValue.props) {
195 propItems.push(`${prop}={${printPlace(value)}}`);
196 }
197 const props = propItems.length !== 0 ? " " + propItems.join(" ") : "";