[hir][be] Use a Map to store ObjectExpression.properties
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
bb91cbbf62a148379c0c96ea3cd6b378d8b486e9
5 files changed
+6
-6
compiler/forget/src/HIR/BuildHIR.ts
+2
-2
@@ -682,7 +682,7 @@ function lowerExpression(
682
case "ObjectExpression": {
683
const expr = exprPath as NodePath<t.ObjectExpression>;
684
const propertyPaths = expr.get("properties");
685
- const properties: { [name: string]: Place } = {};
685
+ const properties: Map<string, Place> = new Map();
686
for (const propertyPath of propertyPaths) {
687
todoInvariant(
688
propertyPath.isObjectProperty(),
@@ -696,7 +696,7 @@ function lowerExpression(
696
"Handle non-expression object values"
697
);
698
const value = lowerExpressionToPlace(builder, valuePath);
699
- properties[key.name] = value;
699
+ properties.set(key.name, value);
700
}
701
return {
702
kind: "ObjectExpression",
compiler/forget/src/HIR/Codegen.ts
+1
-1
@@ -200,7 +200,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array<t.Statement>) {
200
case "ObjectExpression": {
201
const properties = [];
202
if (instrValue.properties !== null) {
203
- for (const [property, value] of Object.entries(instrValue.properties)) {
203
+ for (const [property, value] of instrValue.properties) {
204
properties.push(
205
t.objectProperty(t.stringLiteral(property), codegenPlace(cx, value))
206
);
compiler/forget/src/HIR/HIR.ts
+1
-1
@@ -190,7 +190,7 @@ export type InstructionData =
190
}
191
| {
192
kind: "ObjectExpression";
193
- properties: { [property: string]: Place } | null; // null === empty object
193
+ properties: Map<string, Place> | null; // null === empty object
194
}
195
| { kind: "ArrayExpression"; elements: Array<Place> }
196
compiler/forget/src/HIR/InferReferenceEffects.ts
+1
-1
@@ -526,7 +526,7 @@ function inferBlock(env: Environment, block: BasicBlock) {
526
valueKind = ValueKind.Mutable;
527
// Object construction captures but does not modify the key/property values
528
if (instrValue.properties !== null) {
529
- for (const [_key, value] of Object.entries(instrValue.properties)) {
529
+ for (const [_key, value] of instrValue.properties) {
530
env.reference(value, Effect.Read);
531
}
532
}
compiler/forget/src/HIR/PrintHIR.ts
+1
-1
@@ -161,7 +161,7 @@ function printInstructionValue(instrValue: InstructionValue): string {
161
case "ObjectExpression": {
162
const properties = [];
163
if (instrValue.properties !== null) {
164
- for (const [key, value] of Object.entries(instrValue.properties)) {
164
+ for (const [key, value] of instrValue.properties) {
165
properties.push(`${key}: ${printPlace(value)}`);
166
}
167
}