Skip to content

Commit 55548b6

Browse files
committed
in DictLiteralNode evaluate consecutively keys and values, not keys first and then values
1 parent 2a89f1b commit 55548b6

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/literal/DictLiteralNode.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,21 @@ protected DynamicDictLiteralNode(ExpressionNode[] keys, ExpressionNode[] values)
104104
}
105105
}
106106

107-
static final class Keys {
108-
public final Object[] keys;
109-
public final boolean allStrings;
110-
111-
Keys(Object[] keys, boolean allStrings) {
112-
this.keys = keys;
113-
this.allStrings = allStrings;
114-
}
115-
}
116-
117107
@ExplodeLoop
118-
private Keys evalKeys(VirtualFrame frame) {
108+
private HashingStorage eval(VirtualFrame frame, PythonLanguage lang, ConditionProfile hasFrame) {
119109
boolean allStrings = true;
120110
Object[] evalKeys = new Object[this.keys.length];
111+
Object[] evalValues = new Object[this.values.length];
121112
for (int i = 0; i < values.length; i++) {
122113
evalKeys[i] = keys[i].execute(frame);
123-
if (!(evalKeys[i] instanceof String)) {
114+
evalValues[i] = values[i].execute(frame);
115+
if (allStrings && !(evalKeys[i] instanceof String)) {
124116
allStrings = false;
125117
}
126118
}
127-
return new Keys(evalKeys, allStrings);
128-
}
129-
130-
@ExplodeLoop
131-
private HashingStorage evalAndSetValues(VirtualFrame frame, HashingStorage dictStorage, Keys evalKeys, ConditionProfile hasFrame) {
132-
HashingStorage storage = dictStorage;
119+
HashingStorage storage = PDict.createNewStorage(lang, allStrings, evalKeys.length);
133120
for (int i = 0; i < values.length; i++) {
134-
Object val = values[i].execute(frame);
135-
storage = libs[i].setItemWithFrame(storage, evalKeys.keys[i], val, hasFrame, frame);
121+
storage = libs[i].setItemWithFrame(storage, evalKeys[i], evalValues[i], hasFrame, frame);
136122
}
137123
return storage;
138124
}
@@ -141,9 +127,7 @@ private HashingStorage evalAndSetValues(VirtualFrame frame, HashingStorage dictS
141127
public PDict create(VirtualFrame frame,
142128
@CachedLanguage PythonLanguage lang,
143129
@Cached("createBinaryProfile()") ConditionProfile hasFrame) {
144-
Keys evalKeys = evalKeys(frame);
145-
HashingStorage dictStorage = PDict.createNewStorage(lang, evalKeys.allStrings, evalKeys.keys.length);
146-
dictStorage = evalAndSetValues(frame, dictStorage, evalKeys, hasFrame);
130+
HashingStorage dictStorage = eval(frame, lang, hasFrame);
147131
return factory.createDict(dictStorage);
148132
}
149133
}

0 commit comments

Comments
 (0)