|
98 | 98 | import com.oracle.graal.python.builtins.objects.str.StringNodes.JoinInternalNode;
|
99 | 99 | import com.oracle.graal.python.builtins.objects.str.StringNodes.SpliceNode;
|
100 | 100 | import com.oracle.graal.python.builtins.objects.str.StringNodes.StringLenNode;
|
| 101 | +import com.oracle.graal.python.builtins.objects.str.StringNodes.StringMaterializeNode; |
101 | 102 | import com.oracle.graal.python.builtins.objects.str.StringUtils.StripKind;
|
102 | 103 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
103 | 104 | import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
|
| 105 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode; |
104 | 106 | import com.oracle.graal.python.nodes.ErrorMessages;
|
105 | 107 | import com.oracle.graal.python.nodes.PGuards;
|
106 | 108 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
@@ -404,30 +406,58 @@ String doSSSimple(String self, String other) {
|
404 | 406 | return self;
|
405 | 407 | }
|
406 | 408 |
|
407 |
| - @Specialization(guards = "!concatGuard(self, other.getCharSequence())") |
408 |
| - String doSSSimple(String self, PString other) { |
| 409 | + @Specialization(guards = "!concatGuard(self, other.getCharSequence())", limit = "1") |
| 410 | + Object doSSSimple(String self, PString other, |
| 411 | + @Cached StringMaterializeNode materializeNode, |
| 412 | + @Cached IsSameTypeNode isSameType, |
| 413 | + @Cached BranchProfile isSameBranch, |
| 414 | + @CachedLibrary("other") PythonObjectLibrary lib) { |
409 | 415 | if (LazyString.length(self, leftProfile1, leftProfile2) == 0) {
|
410 | 416 | // result type has to be str
|
411 |
| - return toString(other.getCharSequence()); |
| 417 | + if (isSameType.execute(lib.getLazyPythonClass(other), PythonBuiltinClassType.PString)) { |
| 418 | + isSameBranch.enter(); |
| 419 | + return other; |
| 420 | + } |
| 421 | + return materializeNode.execute(other); |
412 | 422 | }
|
413 | 423 | return self;
|
414 | 424 | }
|
415 | 425 |
|
416 |
| - @Specialization(guards = "!concatGuard(self.getCharSequence(), other)") |
417 |
| - String doSSSimple(PString self, String other) { |
| 426 | + @Specialization(guards = "!concatGuard(self.getCharSequence(), other)", limit = "1") |
| 427 | + Object doSSSimple(PString self, String other, |
| 428 | + @Cached StringMaterializeNode materializeNode, |
| 429 | + @Cached IsSameTypeNode isSameType, |
| 430 | + @Cached BranchProfile isSameBranch, |
| 431 | + @CachedLibrary("self") PythonObjectLibrary lib) { |
418 | 432 | if (LazyString.length(self.getCharSequence(), leftProfile1, leftProfile2) == 0) {
|
419 | 433 | return other;
|
420 | 434 | }
|
421 | 435 | // result type has to be str
|
422 |
| - return toString(self.getCharSequence()); |
| 436 | + if (isSameType.execute(lib.getLazyPythonClass(self), PythonBuiltinClassType.PString)) { |
| 437 | + isSameBranch.enter(); |
| 438 | + return self; |
| 439 | + } |
| 440 | + return materializeNode.execute(self); |
423 | 441 | }
|
424 | 442 |
|
425 | 443 | @Specialization(guards = "!concatGuard(self.getCharSequence(), other.getCharSequence())")
|
426 |
| - String doSSSimple(PString self, PString other) { |
| 444 | + Object doSSSimple(PString self, PString other, |
| 445 | + @Cached StringMaterializeNode materializeNode, |
| 446 | + @Cached IsSameTypeNode isSameType, |
| 447 | + @Cached BranchProfile isSameBranch, |
| 448 | + @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
427 | 449 | if (LazyString.length(self.getCharSequence(), leftProfile1, leftProfile2) == 0) {
|
428 |
| - return toString(other.getCharSequence()); |
| 450 | + if (isSameType.execute(lib.getLazyPythonClass(other), PythonBuiltinClassType.PString)) { |
| 451 | + isSameBranch.enter(); |
| 452 | + return other; |
| 453 | + } |
| 454 | + return materializeNode.execute(other); |
429 | 455 | }
|
430 |
| - return toString(self.getCharSequence()); |
| 456 | + if (isSameType.execute(lib.getLazyPythonClass(self), PythonBuiltinClassType.PString)) { |
| 457 | + isSameBranch.enter(); |
| 458 | + return self; |
| 459 | + } |
| 460 | + return materializeNode.execute(self); |
431 | 461 | }
|
432 | 462 |
|
433 | 463 | @Specialization(guards = "concatGuard(self.getCharSequence(), other)")
|
@@ -476,11 +506,6 @@ private static String stringConcat(CharSequence left, CharSequence right) {
|
476 | 506 | return left.toString() + right.toString();
|
477 | 507 | }
|
478 | 508 |
|
479 |
| - @TruffleBoundary |
480 |
| - private static String toString(CharSequence cs) { |
481 |
| - return cs.toString(); |
482 |
| - } |
483 |
| - |
484 | 509 | @Specialization(guards = "isString(self)")
|
485 | 510 | Object doSNative(VirtualFrame frame, Object self, PythonAbstractNativeObject other,
|
486 | 511 | @Cached CastToJavaStringNode cast,
|
|
0 commit comments