Skip to content

Commit c0194fe

Browse files
committed
SetBuiltins: __and__ missing specialization for adding Strings
1 parent bb2f85c commit c0194fe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.oracle.graal.python.builtins.objects.set;
2727

28+
import static com.oracle.graal.python.builtins.objects.common.HashingStorage.getSlowPathEquivalence;
2829
import static com.oracle.graal.python.nodes.SpecialMethodNames.__AND__;
2930
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CONTAINS__;
3031
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
@@ -61,6 +62,7 @@
6162
import com.oracle.graal.python.runtime.exception.PException;
6263
import com.oracle.truffle.api.CompilerDirectives;
6364
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
65+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6466
import com.oracle.truffle.api.dsl.Cached;
6567
import com.oracle.truffle.api.dsl.Fallback;
6668
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -149,6 +151,26 @@ Object run(PBaseSet self, PBaseSet other) {
149151
abstract static class AndNode extends PythonBinaryBuiltinNode {
150152
@Child private HashingStorageNodes.IntersectNode intersectNode;
151153

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+
152174
private HashingStorageNodes.IntersectNode getIntersectNode() {
153175
if (intersectNode == null) {
154176
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)