121121import com .oracle .graal .python .builtins .objects .slice .SliceNodes .ComputeIndices ;
122122import com .oracle .graal .python .builtins .objects .str .StringBuiltinsClinicProviders .FormatNodeClinicProviderGen ;
123123import com .oracle .graal .python .builtins .objects .str .StringBuiltinsClinicProviders .SplitNodeClinicProviderGen ;
124- import com .oracle .graal .python .builtins .objects .str .StringBuiltinsFactory .LtNodeFactory ;
125124import com .oracle .graal .python .builtins .objects .str .StringNodes .CastToJavaStringCheckedNode ;
126125import com .oracle .graal .python .builtins .objects .str .StringNodes .CastToTruffleStringCheckedNode ;
127126import com .oracle .graal .python .builtins .objects .str .StringNodes .JoinInternalNode ;
164163import com .oracle .graal .python .runtime .formatting .StringFormatProcessor ;
165164import com .oracle .graal .python .runtime .formatting .TextFormatter ;
166165import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
166+ import com .oracle .graal .python .util .IntPredicate ;
167167import com .oracle .truffle .api .CompilerAsserts ;
168168import com .oracle .truffle .api .CompilerDirectives ;
169169import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
177177import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
178178import com .oracle .truffle .api .dsl .GenerateUncached ;
179179import com .oracle .truffle .api .dsl .ImportStatic ;
180- import com .oracle .truffle .api .dsl .NeverDefault ;
181180import com .oracle .truffle .api .dsl .Specialization ;
182181import com .oracle .truffle .api .dsl .TypeSystemReference ;
183182import com .oracle .truffle .api .frame .VirtualFrame ;
@@ -385,20 +384,23 @@ static Object doGeneric(Node inliningTarget, Object self, Object other, boolean
385384 }
386385 }
387386
388- abstract static class StringCmpOpBaseNode extends PythonBinaryBuiltinNode {
387+ @ GenerateInline
388+ @ GenerateCached (false )
389+ abstract static class StringCmpOpHelperNode extends Node {
390+
391+ abstract Object execute (Node inliningTarget , Object self , Object other , IntPredicate resultProcessor );
392+
389393 @ Specialization
390- boolean doStrings (TruffleString self , TruffleString other ,
391- @ Shared ( "compareIntsUtf32" ) @ Cached TruffleString .CompareIntsUTF32Node compareIntsUTF32Node ) {
392- return processResult (StringUtils .compareStrings (self , other , compareIntsUTF32Node ));
394+ static boolean doStrings (TruffleString self , TruffleString other , IntPredicate resultProcessor ,
395+ @ Shared @ Cached ( inline = false ) TruffleString .CompareIntsUTF32Node compareIntsUTF32Node ) {
396+ return resultProcessor . test (StringUtils .compareStrings (self , other , compareIntsUTF32Node ));
393397 }
394398
395399 @ Specialization
396- @ SuppressWarnings ("truffle-static-method" )
397- Object doGeneric (Object self , Object other ,
398- @ Bind ("this" ) Node inliningTarget ,
400+ static Object doGeneric (Node inliningTarget , Object self , Object other , IntPredicate resultProcessor ,
399401 @ Cached CastToTruffleStringCheckedNode castSelfNode ,
400402 @ Cached CastToTruffleStringNode castOtherNode ,
401- @ Shared ( "compareIntsUtf32" ) @ Cached TruffleString .CompareIntsUTF32Node compareIntsUTF32Node ,
403+ @ Shared @ Cached ( inline = false ) TruffleString .CompareIntsUTF32Node compareIntsUTF32Node ,
402404 @ Cached InlinedBranchProfile noStringBranch ) {
403405 TruffleString selfStr = castSelfNode .cast (inliningTarget , self , ErrorMessages .REQUIRES_STR_OBJECT_BUT_RECEIVED_P , T___EQ__ , self );
404406 TruffleString otherStr ;
@@ -408,13 +410,7 @@ Object doGeneric(Object self, Object other,
408410 noStringBranch .enter (inliningTarget );
409411 return PNotImplemented .NOT_IMPLEMENTED ;
410412 }
411- return doStrings (selfStr , otherStr , compareIntsUTF32Node );
412- }
413-
414- @ SuppressWarnings ("unused" )
415- boolean processResult (int cmpResult ) {
416- CompilerAsserts .neverPartOfCompilation ();
417- throw new IllegalStateException ("should not be reached" );
413+ return doStrings (selfStr , otherStr , resultProcessor , compareIntsUTF32Node );
418414 }
419415 }
420416
@@ -461,42 +457,49 @@ static Object doIt(Object self, Object other,
461457
462458 @ Builtin (name = J___LT__ , minNumOfPositionalArgs = 2 )
463459 @ GenerateNodeFactory
464- public abstract static class LtNode extends StringCmpOpBaseNode {
465- @ Override
466- boolean processResult (int cmpResult ) {
467- return cmpResult < 0 ;
468- }
460+ public abstract static class LtNode extends PythonBinaryBuiltinNode {
469461
470- @ NeverDefault
471- public static LtNode create () {
472- return LtNodeFactory .create ();
462+ @ Specialization
463+ static Object doIt (Object self , Object other ,
464+ @ Bind ("this" ) Node inliningTarget ,
465+ @ Cached StringCmpOpHelperNode stringCmpOpHelperNode ) {
466+ return stringCmpOpHelperNode .execute (inliningTarget , self , other , r -> r < 0 );
473467 }
474468 }
475469
476470 @ Builtin (name = J___LE__ , minNumOfPositionalArgs = 2 )
477471 @ GenerateNodeFactory
478- public abstract static class LeNode extends StringCmpOpBaseNode {
479- @ Override
480- boolean processResult (int cmpResult ) {
481- return cmpResult <= 0 ;
472+ public abstract static class LeNode extends PythonBinaryBuiltinNode {
473+
474+ @ Specialization
475+ static Object doIt (Object self , Object other ,
476+ @ Bind ("this" ) Node inliningTarget ,
477+ @ Cached StringCmpOpHelperNode stringCmpOpHelperNode ) {
478+ return stringCmpOpHelperNode .execute (inliningTarget , self , other , r -> r <= 0 );
482479 }
483480 }
484481
485482 @ Builtin (name = J___GT__ , minNumOfPositionalArgs = 2 )
486483 @ GenerateNodeFactory
487- public abstract static class GtNode extends StringCmpOpBaseNode {
488- @ Override
489- boolean processResult (int cmpResult ) {
490- return cmpResult > 0 ;
484+ public abstract static class GtNode extends PythonBinaryBuiltinNode {
485+
486+ @ Specialization
487+ static Object doIt (Object self , Object other ,
488+ @ Bind ("this" ) Node inliningTarget ,
489+ @ Cached StringCmpOpHelperNode stringCmpOpHelperNode ) {
490+ return stringCmpOpHelperNode .execute (inliningTarget , self , other , r -> r > 0 );
491491 }
492492 }
493493
494494 @ Builtin (name = J___GE__ , minNumOfPositionalArgs = 2 )
495495 @ GenerateNodeFactory
496- public abstract static class GeNode extends StringCmpOpBaseNode {
497- @ Override
498- boolean processResult (int cmpResult ) {
499- return cmpResult >= 0 ;
496+ public abstract static class GeNode extends PythonBinaryBuiltinNode {
497+
498+ @ Specialization
499+ static Object doIt (Object self , Object other ,
500+ @ Bind ("this" ) Node inliningTarget ,
501+ @ Cached StringCmpOpHelperNode stringCmpOpHelperNode ) {
502+ return stringCmpOpHelperNode .execute (inliningTarget , self , other , r -> r >= 0 );
500503 }
501504 }
502505
0 commit comments