[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.
This commit is contained in:
Sathya Gunasekaran
2022-10-24 16:04:18 +01:00
parent f54d121d71
commit bb91cbbf62
5 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -682,7 +682,7 @@ function lowerExpression(
case "ObjectExpression": {
const expr = exprPath as NodePath<t.ObjectExpression>;
const propertyPaths = expr.get("properties");
const properties: { [name: string]: Place } = {};
const properties: Map<string, Place> = new Map();
for (const propertyPath of propertyPaths) {
todoInvariant(
propertyPath.isObjectProperty(),
@@ -696,7 +696,7 @@ function lowerExpression(
"Handle non-expression object values"
);
const value = lowerExpressionToPlace(builder, valuePath);
properties[key.name] = value;
properties.set(key.name, value);
}
return {
kind: "ObjectExpression",
+1 -1
View File
@@ -200,7 +200,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array<t.Statement>) {
case "ObjectExpression": {
const properties = [];
if (instrValue.properties !== null) {
for (const [property, value] of Object.entries(instrValue.properties)) {
for (const [property, value] of instrValue.properties) {
properties.push(
t.objectProperty(t.stringLiteral(property), codegenPlace(cx, value))
);
+1 -1
View File
@@ -190,7 +190,7 @@ export type InstructionData =
}
| {
kind: "ObjectExpression";
properties: { [property: string]: Place } | null; // null === empty object
properties: Map<string, Place> | null; // null === empty object
}
| { kind: "ArrayExpression"; elements: Array<Place> }
@@ -526,7 +526,7 @@ function inferBlock(env: Environment, block: BasicBlock) {
valueKind = ValueKind.Mutable;
// Object construction captures but does not modify the key/property values
if (instrValue.properties !== null) {
for (const [_key, value] of Object.entries(instrValue.properties)) {
for (const [_key, value] of instrValue.properties) {
env.reference(value, Effect.Read);
}
}
+1 -1
View File
@@ -161,7 +161,7 @@ function printInstructionValue(instrValue: InstructionValue): string {
case "ObjectExpression": {
const properties = [];
if (instrValue.properties !== null) {
for (const [key, value] of Object.entries(instrValue.properties)) {
for (const [key, value] of instrValue.properties) {
properties.push(`${key}: ${printPlace(value)}`);
}
}