|
25 | 25 | */
|
26 | 26 | package com.oracle.graal.python.builtins.objects.set;
|
27 | 27 |
|
| 28 | +import static com.oracle.graal.python.builtins.objects.common.HashingStorage.getSlowPathEquivalence; |
28 | 29 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__AND__;
|
29 | 30 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CONTAINS__;
|
30 | 31 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
|
61 | 62 | import com.oracle.graal.python.runtime.exception.PException;
|
62 | 63 | import com.oracle.truffle.api.CompilerDirectives;
|
63 | 64 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
| 65 | +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
64 | 66 | import com.oracle.truffle.api.dsl.Cached;
|
65 | 67 | import com.oracle.truffle.api.dsl.Fallback;
|
66 | 68 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
@@ -149,6 +151,26 @@ Object run(PBaseSet self, PBaseSet other) {
|
149 | 151 | abstract static class AndNode extends PythonBinaryBuiltinNode {
|
150 | 152 | @Child private HashingStorageNodes.IntersectNode intersectNode;
|
151 | 153 |
|
| 154 | + @TruffleBoundary |
| 155 | + private HashingStorage getStringAsHashingStorage(String str) { |
| 156 | + HashingStorage storage = EconomicMapStorage.create(str.length(), true); |
| 157 | + for (int i = 0; i < str.length(); i++) { |
| 158 | + String key = String.valueOf(str.charAt(i)); |
| 159 | + storage.setItem(key, PNone.NO_VALUE, getSlowPathEquivalence(key)); |
| 160 | + } |
| 161 | + return storage; |
| 162 | + } |
| 163 | + |
| 164 | + @Specialization |
| 165 | + PBaseSet doPBaseSet(PSet left, String right) { |
| 166 | + return factory().createSet(getIntersectNode().execute(left.getDictStorage(), getStringAsHashingStorage(right))); |
| 167 | + } |
| 168 | + |
| 169 | + @Specialization |
| 170 | + PBaseSet doPBaseSet(PFrozenSet left, String right) { |
| 171 | + return factory().createFrozenSet(getIntersectNode().execute(left.getDictStorage(), getStringAsHashingStorage(right))); |
| 172 | + } |
| 173 | + |
152 | 174 | private HashingStorageNodes.IntersectNode getIntersectNode() {
|
153 | 175 | if (intersectNode == null) {
|
154 | 176 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
|
0 commit comments