|
61 | 61 | import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject;
|
62 | 62 | import com.oracle.graal.python.builtins.objects.common.IndexNodes.NormalizeIndexNode;
|
63 | 63 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
| 64 | +import com.oracle.graal.python.builtins.objects.function.PArguments; |
64 | 65 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
65 | 66 | import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
|
| 67 | +import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary; |
66 | 68 | import com.oracle.graal.python.builtins.objects.slice.PSlice;
|
67 | 69 | import com.oracle.graal.python.builtins.objects.str.PString;
|
68 | 70 | import com.oracle.graal.python.nodes.argument.ReadArgumentNode;
|
|
86 | 88 | import com.oracle.truffle.api.dsl.Specialization;
|
87 | 89 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
88 | 90 | import com.oracle.truffle.api.frame.VirtualFrame;
|
| 91 | +import com.oracle.truffle.api.library.CachedLibrary; |
89 | 92 |
|
90 | 93 | @CoreFunctions(extendClasses = PythonBuiltinClassType.PTuple)
|
91 | 94 | public class TupleBuiltins extends PythonBuiltins {
|
@@ -584,22 +587,15 @@ public long getHash(PTuple self) {
|
584 | 587 | public long computeHash(VirtualFrame frame, PTuple self,
|
585 | 588 | @Cached("create()") SequenceStorageNodes.LenNode getLen,
|
586 | 589 | @Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode,
|
587 |
| - @Cached("create()") BuiltinFunctions.HashNode hashNode, |
588 |
| - @Cached("createLossy()") CoerceToJavaLongNode castToLongNode) { |
| 590 | + @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary lib) { |
589 | 591 | // adapted from https://github.com/python/cpython/blob/v3.6.5/Objects/tupleobject.c#L345
|
590 | 592 | SequenceStorage tupleStore = self.getSequenceStorage();
|
591 | 593 | int len = getLen.execute(tupleStore);
|
592 | 594 | long multiplier = 0xf4243;
|
593 | 595 | long hash = 0x345678;
|
594 |
| - long tmp; |
595 | 596 | for (int i = 0; i < len; i++) {
|
596 | 597 | Object item = getItemNode.execute(frame, tupleStore, i);
|
597 |
| - Object hashValue = hashNode.execute(frame, item); |
598 |
| - tmp = castToLongNode.execute(hashValue); |
599 |
| - if (tmp == -1) { |
600 |
| - return -1; |
601 |
| - } |
602 |
| - |
| 598 | + long tmp = lib.hashWithState(item, PArguments.getThreadState(frame)); |
603 | 599 | hash = (hash ^ tmp) * multiplier;
|
604 | 600 | multiplier += 82520 + len + len;
|
605 | 601 | }
|
|
0 commit comments