14
14
import com .oracle .truffle .api .dsl .Cached ;
15
15
import com .oracle .truffle .api .dsl .ImportStatic ;
16
16
import com .oracle .truffle .api .dsl .Specialization ;
17
- import com .oracle .truffle .api .frame .VirtualFrame ;
18
17
import com .oracle .truffle .api .library .CachedLibrary ;
19
18
import com .oracle .truffle .api .object .Shape ;
20
19
import com .oracle .truffle .api .profiles .ConditionProfile ;
@@ -417,7 +416,7 @@ public abstract static class TimeStrftimePrimitiveNode extends PrimitiveArrayArg
417
416
@ Specialization (
418
417
guards = { "equalNode.execute(libFormat.getRope(format), cachedFormat)" },
419
418
limit = "getLanguage().options.TIME_FORMAT_CACHE" )
420
- protected RubyString timeStrftime (VirtualFrame frame , RubyTime time , Object format ,
419
+ protected RubyString timeStrftime (RubyTime time , Object format ,
421
420
@ CachedLibrary (limit = "2" ) RubyStringLibrary libFormat ,
422
421
@ Cached ("libFormat.getRope(format)" ) Rope cachedFormat ,
423
422
@ Cached (value = "compilePattern(cachedFormat)" , dimensions = 1 ) Token [] pattern ,
@@ -437,6 +436,24 @@ protected RubyString timeStrftime(VirtualFrame frame, RubyTime time, Object form
437
436
}
438
437
}
439
438
439
+ @ TruffleBoundary
440
+ @ Specialization (guards = "libFormat.isRubyString(format)" )
441
+ protected RubyString timeStrftime (RubyTime time , Object format ,
442
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libFormat ,
443
+ @ Cached RopeNodes .ConcatNode concatNode ,
444
+ @ Cached RopeNodes .SubstringNode substringNode ) {
445
+ final Token [] pattern = compilePattern (libFormat .getRope (format ));
446
+ if (formatToRopeBuilderCanBeFast (pattern ) && yearIsFast (time )) {
447
+ return makeStringNode .fromRope (RubyDateFormatter .formatToRopeBuilderFast (
448
+ pattern ,
449
+ time .dateTime ,
450
+ concatNode ,
451
+ substringNode ));
452
+ } else {
453
+ return makeStringNode .fromBuilderUnsafe (formatTime (time , pattern ), CodeRange .CR_UNKNOWN );
454
+ }
455
+ }
456
+
440
457
protected boolean formatToRopeBuilderCanBeFast (Token [] pattern ) {
441
458
return RubyDateFormatter .formatToRopeBuilderCanBeFast (pattern );
442
459
}
@@ -447,15 +464,6 @@ protected boolean yearIsFast(RubyTime time) {
447
464
return year >= 1000 && year <= 9999 ;
448
465
}
449
466
450
- @ Specialization (guards = "libFormat.isRubyString(format)" )
451
- protected RubyString timeStrftime (VirtualFrame frame , RubyTime time , Object format ,
452
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libFormat ) {
453
- final Token [] pattern = compilePattern (libFormat .getRope (format ));
454
- return makeStringNode .fromBuilderUnsafe (
455
- formatTime (time , pattern ),
456
- CodeRange .CR_UNKNOWN );
457
- }
458
-
459
467
protected Token [] compilePattern (Rope format ) {
460
468
return RubyDateFormatter .compilePattern (format , false , getContext (), this );
461
469
}
0 commit comments