|
132 | 132 | import com.oracle.graal.python.nodes.PGuards; |
133 | 133 | import com.oracle.graal.python.nodes.PRaiseNode; |
134 | 134 | import com.oracle.graal.python.nodes.StringLiterals; |
135 | | -import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode; |
136 | 135 | import com.oracle.graal.python.nodes.call.CallNode; |
137 | 136 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode; |
138 | 137 | import com.oracle.graal.python.nodes.object.GetClassNode; |
@@ -298,45 +297,42 @@ static Object doGeneric(Object obj, Object encodingObj, Object errorsObj, |
298 | 297 | } |
299 | 298 | } |
300 | 299 |
|
301 | | - @CApiBuiltin(ret = PyObject, args = {PyObject}, call = Ignored) |
| 300 | + @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Ignored) |
302 | 301 | abstract static class PyTruffleUnicode_LookupAndIntern extends CApiUnaryBuiltinNode { |
303 | | - @Specialization |
304 | | - static Object withTS(TruffleString str, |
305 | | - @Bind("this") Node inliningTarget, |
306 | | - @Exclusive @Cached StringNodes.InternStringNode internNode, |
307 | | - @Exclusive @Cached HashingStorageGetItem getItem, |
308 | | - @Exclusive @Cached HashingStorageSetItem setItem, |
309 | | - @Exclusive @Cached PythonObjectFactory.Lazy factory) { |
310 | | - PDict dict = getCApiContext(inliningTarget).getInternedUnicode(); |
311 | | - if (dict == null) { |
312 | | - dict = factory.get(inliningTarget).createDict(); |
313 | | - getCApiContext(inliningTarget).setInternedUnicode(dict); |
314 | | - } |
315 | | - Object interned = getItem.execute(inliningTarget, dict.getDictStorage(), str); |
316 | | - if (interned == null) { |
317 | | - interned = internNode.execute(inliningTarget, str); |
318 | | - dict.setDictStorage(setItem.execute(inliningTarget, dict.getDictStorage(), str, interned)); |
319 | | - } |
320 | | - return interned; |
321 | | - } |
322 | 302 |
|
323 | 303 | @Specialization |
324 | 304 | static Object withPString(PString str, |
325 | 305 | @Bind("this") Node inliningTarget, |
326 | 306 | @Cached PyUnicodeCheckExactNode unicodeCheckExactNode, |
327 | | - @Cached ReadAttributeFromDynamicObjectNode readNode, |
328 | | - @Exclusive @Cached StringNodes.InternStringNode internNode, |
329 | | - @Exclusive @Cached HashingStorageGetItem getItem, |
330 | | - @Exclusive @Cached HashingStorageSetItem setItem, |
331 | | - @Exclusive @Cached PythonObjectFactory.Lazy factory) { |
| 307 | + @Cached CastToTruffleStringNode cast, |
| 308 | + @Cached StringNodes.IsInternedStringNode isInternedStringNode, |
| 309 | + @Cached StringNodes.InternStringNode internNode, |
| 310 | + @Cached HashingStorageGetItem getItem, |
| 311 | + @Cached HashingStorageSetItem setItem, |
| 312 | + @Cached PythonObjectFactory.Lazy factory) { |
332 | 313 | if (!unicodeCheckExactNode.execute(inliningTarget, str)) { |
333 | 314 | return getNativeNull(inliningTarget); |
334 | 315 | } |
335 | | - boolean isInterned = readNode.execute(str, PString.INTERNED) != PNone.NO_VALUE; |
| 316 | + /* |
| 317 | + * TODO this is not integrated with str.intern, pointer comparisons of two str.intern'ed |
| 318 | + * string may still yield failse |
| 319 | + */ |
| 320 | + boolean isInterned = isInternedStringNode.execute(inliningTarget, str); |
336 | 321 | if (isInterned) { |
337 | 322 | return str; |
338 | 323 | } |
339 | | - return withTS(str.getValueUncached(), inliningTarget, internNode, getItem, setItem, factory); |
| 324 | + TruffleString ts = cast.execute(inliningTarget, str); |
| 325 | + PDict dict = getCApiContext(inliningTarget).getInternedUnicode(); |
| 326 | + if (dict == null) { |
| 327 | + dict = factory.get(inliningTarget).createDict(); |
| 328 | + getCApiContext(inliningTarget).setInternedUnicode(dict); |
| 329 | + } |
| 330 | + Object interned = getItem.execute(inliningTarget, dict.getDictStorage(), ts); |
| 331 | + if (interned == null) { |
| 332 | + interned = internNode.execute(inliningTarget, str); |
| 333 | + dict.setDictStorage(setItem.execute(inliningTarget, dict.getDictStorage(), ts, interned)); |
| 334 | + } |
| 335 | + return interned; |
340 | 336 | } |
341 | 337 |
|
342 | 338 | @Fallback |
|
0 commit comments