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 ;
@@ -374,28 +373,36 @@ public abstract static class TimeStrftimePrimitiveNode extends PrimitiveArrayArg
374
373
@ Specialization (
375
374
guards = { "equalNode.execute(libFormat.getRope(format), cachedFormat)" },
376
375
limit = "getLanguage().options.TIME_FORMAT_CACHE" )
377
- protected RubyString timeStrftime (VirtualFrame frame , RubyTime time , Object format ,
376
+ protected RubyString timeStrftime (RubyTime time , Object format ,
378
377
@ CachedLibrary (limit = "2" ) RubyStringLibrary libFormat ,
379
378
@ Cached ("libFormat.getRope(format)" ) Rope cachedFormat ,
380
379
@ Cached (value = "compilePattern(cachedFormat)" , dimensions = 1 ) Token [] pattern ,
381
380
@ Cached RopeNodes .EqualNode equalNode ,
382
- @ Cached ("formatToRopeBuilderCanBeFast (pattern)" ) boolean canUseFast ,
381
+ @ Cached ("formatCanBeFast (pattern)" ) boolean canUseFast ,
383
382
@ Cached ConditionProfile yearIsFastProfile ,
384
- @ Cached RopeNodes .ConcatNode concatNode ,
385
- @ Cached RopeNodes .SubstringNode substringNode ) {
383
+ @ Cached RopeNodes .ConcatNode concatNode ) {
386
384
if (canUseFast && yearIsFastProfile .profile (yearIsFast (time ))) {
387
- return makeStringNode .fromRope (RubyDateFormatter .formatToRopeBuilderFast (
388
- pattern ,
389
- time .dateTime ,
390
- concatNode ,
391
- substringNode ));
385
+ return makeStringNode .fromRope (RubyDateFormatter .formatToRopeFast (pattern , time .dateTime , concatNode ));
392
386
} else {
393
387
return makeStringNode .fromBuilderUnsafe (formatTime (time , pattern ), CodeRange .CR_UNKNOWN );
394
388
}
395
389
}
396
390
397
- protected boolean formatToRopeBuilderCanBeFast (Token [] pattern ) {
398
- return RubyDateFormatter .formatToRopeBuilderCanBeFast (pattern );
391
+ @ TruffleBoundary
392
+ @ Specialization (guards = "libFormat.isRubyString(format)" )
393
+ protected RubyString timeStrftime (RubyTime time , Object format ,
394
+ @ CachedLibrary (limit = "2" ) RubyStringLibrary libFormat ,
395
+ @ Cached RopeNodes .ConcatNode concatNode ) {
396
+ final Token [] pattern = compilePattern (libFormat .getRope (format ));
397
+ if (formatCanBeFast (pattern ) && yearIsFast (time )) {
398
+ return makeStringNode .fromRope (RubyDateFormatter .formatToRopeFast (pattern , time .dateTime , concatNode ));
399
+ } else {
400
+ return makeStringNode .fromBuilderUnsafe (formatTime (time , pattern ), CodeRange .CR_UNKNOWN );
401
+ }
402
+ }
403
+
404
+ protected boolean formatCanBeFast (Token [] pattern ) {
405
+ return RubyDateFormatter .formatCanBeFast (pattern );
399
406
}
400
407
401
408
protected boolean yearIsFast (RubyTime time ) {
@@ -404,15 +411,6 @@ protected boolean yearIsFast(RubyTime time) {
404
411
return year >= 1000 && year <= 9999 ;
405
412
}
406
413
407
- @ Specialization (guards = "libFormat.isRubyString(format)" )
408
- protected RubyString timeStrftime (VirtualFrame frame , RubyTime time , Object format ,
409
- @ CachedLibrary (limit = "2" ) RubyStringLibrary libFormat ) {
410
- final Token [] pattern = compilePattern (libFormat .getRope (format ));
411
- return makeStringNode .fromBuilderUnsafe (
412
- formatTime (time , pattern ),
413
- CodeRange .CR_UNKNOWN );
414
- }
415
-
416
414
protected Token [] compilePattern (Rope format ) {
417
415
return RubyDateFormatter .compilePattern (format , false , getContext (), this );
418
416
}
0 commit comments