|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached; |
44 | 44 |
|
45 | | -import java.util.LinkedHashMap; |
46 | 45 | import java.util.List; |
47 | 46 |
|
48 | 47 | import com.oracle.graal.python.builtins.Builtin; |
|
51 | 50 | import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
52 | 51 | import com.oracle.graal.python.builtins.PythonBuiltins; |
53 | 52 | import com.oracle.graal.python.builtins.PythonOS; |
| 53 | +import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage; |
54 | 54 | import com.oracle.graal.python.builtins.objects.module.PythonModule; |
| 55 | +import com.oracle.graal.python.lib.PyObjectHashNode; |
55 | 56 | import com.oracle.graal.python.nodes.PRaiseNode; |
56 | 57 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; |
57 | 58 | import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode; |
58 | 59 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
59 | 60 | import com.oracle.truffle.api.dsl.GenerateNodeFactory; |
60 | 61 | import com.oracle.truffle.api.dsl.NodeFactory; |
61 | 62 | import com.oracle.truffle.api.dsl.Specialization; |
| 63 | +import com.oracle.truffle.api.strings.TruffleString; |
| 64 | +import com.oracle.truffle.api.strings.TruffleString.HashCodeNode; |
62 | 65 |
|
63 | 66 | @CoreFunctions(defineModule = "pyexpat", os = PythonOS.PLATFORM_WIN32) |
64 | 67 | public final class PyExpatModuleBuiltins extends PythonBuiltins { |
@@ -142,15 +145,17 @@ public void initialize(Python3Core core) { |
142 | 145 | addBuiltinConstant("model", model); |
143 | 146 |
|
144 | 147 | PythonModule errors = core.factory().createPythonModule(toTruffleStringUncached("pyexpat.errors")); |
145 | | - LinkedHashMap<String, Object> codes = new LinkedHashMap<>(ErrorConstant.values().length); |
146 | | - LinkedHashMap<Object, Object> messages = new LinkedHashMap<>(ErrorConstant.values().length); |
| 148 | + EconomicMapStorage codes = EconomicMapStorage.create(ErrorConstant.values().length); |
| 149 | + EconomicMapStorage messages = EconomicMapStorage.create(ErrorConstant.values().length); |
147 | 150 | for (ErrorConstant c : ErrorConstant.values()) { |
148 | | - errors.setAttribute(toTruffleStringUncached(c.name()), toTruffleStringUncached(c.message)); |
149 | | - codes.put(c.message, c.ordinal() + 1); |
150 | | - messages.put(c.ordinal() + 1, c.message); |
| 151 | + TruffleString messageTs = toTruffleStringUncached(c.message); |
| 152 | + errors.setAttribute(toTruffleStringUncached(c.name()), messageTs); |
| 153 | + int id = c.ordinal() + 1; |
| 154 | + codes.putUncachedWithJavaEq(messageTs, PyObjectHashNode.hash(messageTs, HashCodeNode.getUncached()), id); |
| 155 | + messages.putUncachedWithJavaEq(id, PyObjectHashNode.hash(id), c.message); |
151 | 156 | } |
152 | | - errors.setAttribute(toTruffleStringUncached("messages"), core.factory().createDictFromMapGeneric(messages)); |
153 | | - errors.setAttribute(toTruffleStringUncached("codes"), core.factory().createDictFromMap(codes)); |
| 157 | + errors.setAttribute(toTruffleStringUncached("messages"), core.factory().createDict(messages)); |
| 158 | + errors.setAttribute(toTruffleStringUncached("codes"), core.factory().createDict(codes)); |
154 | 159 | addBuiltinConstant("errors", errors); |
155 | 160 | } |
156 | 161 |
|
|
0 commit comments