Skip to content

Commit 6c85c32

Browse files
committed
[Truffle] Use lowerFixnumParameters for time_s_specific.
1 parent 8d40490 commit 6c85c32

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/TimePrimitiveNodes.java

+12-32
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.jruby.truffle.nodes.rubinius;
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
1314
import com.oracle.truffle.api.dsl.Specialization;
1415
import com.oracle.truffle.api.frame.VirtualFrame;
1516
import com.oracle.truffle.api.source.SourceSection;
@@ -46,7 +47,7 @@ public RubyTime timeSNow(VirtualFrame frame, RubyClass timeClass) {
4647
return new RubyTime(timeClass, now(readTimeZoneNode.executeRubyString(frame)), nil());
4748
}
4849

49-
@CompilerDirectives.TruffleBoundary
50+
@TruffleBoundary
5051
private DateTime now(RubyString timeZone) {
5152
return DateTime.now(org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), timeZone.toString()));
5253
}
@@ -68,7 +69,7 @@ public RubyTime timeSDup(RubyTime other) {
6869

6970
}
7071

71-
@RubiniusPrimitive(name = "time_s_specific", needsSelf = false)
72+
@RubiniusPrimitive(name = "time_s_specific", needsSelf = false, lowerFixnumParameters = { 0, 1 })
7273
public static abstract class TimeSSpecificPrimitiveNode extends RubiniusPrimitiveNode {
7374

7475
@Child private ReadTimeZoneNode readTimeZoneNode;
@@ -78,48 +79,27 @@ public TimeSSpecificPrimitiveNode(RubyContext context, SourceSection sourceSecti
7879
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
7980
}
8081

81-
@Specialization(guards = {"isTrue(isUTC)", "isNil(offset)"})
82-
public RubyTime timeSSpecificUTC(long seconds, long nanoseconds, boolean isUTC, Object offset) {
83-
return timeSSpecificUTC((int) seconds, (int) nanoseconds, isUTC, offset);
84-
}
85-
86-
@Specialization(guards = {"isTrue(isUTC)", "isNil(offset)"})
87-
public RubyTime timeSSpecificUTC(long seconds, int nanoseconds, boolean isUTC, Object offset) {
88-
return timeSSpecificUTC((int) seconds, nanoseconds, isUTC, offset);
89-
}
90-
91-
@Specialization(guards = {"isTrue(isUTC)", "isNil(offset)"})
82+
@Specialization(guards = { "isTrue(isUTC)", "isNil(offset)" })
9283
public RubyTime timeSSpecificUTC(int seconds, int nanoseconds, boolean isUTC, Object offset) {
9384
// TODO(CS): overflow checks needed?
9485
final long milliseconds = seconds * 1_000L + (nanoseconds / 1_000_000);
9586
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds), nil());
9687
}
9788

98-
99-
@Specialization(guards = {"!isTrue(isUTC)", "isNil(offset)"})
100-
public RubyTime timeSSpecific(VirtualFrame frame, long seconds, long nanoseconds, boolean isUTC, Object offset) {
101-
return timeSSpecific(frame, (int) seconds, (int) nanoseconds, isUTC, offset);
102-
}
103-
104-
@Specialization(guards = {"!isTrue(isUTC)", "isNil(offset)"})
105-
public RubyTime timeSSpecific(VirtualFrame frame, long seconds, int nanoseconds, boolean isUTC, Object offset) {
106-
return timeSSpecific(frame, (int) seconds, nanoseconds, isUTC, offset);
107-
}
108-
109-
@Specialization(guards = {"!isTrue(isUTC)", "isNil(offset)"})
89+
@Specialization(guards = { "!isTrue(isUTC)", "isNil(offset)" })
11090
public RubyTime timeSSpecific(VirtualFrame frame, int seconds, int nanoseconds, boolean isUTC, Object offset) {
11191
// TODO(CS): overflow checks needed?
11292
final long milliseconds = (long) seconds * 1_000 + ((long) nanoseconds / 1_000_000);
113-
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds, readTimeZoneNode.executeRubyString(frame)), offset);
93+
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), localtime(milliseconds, readTimeZoneNode.executeRubyString(frame)), offset);
11494
}
11595

116-
@CompilerDirectives.TruffleBoundary
117-
public DateTime time(long milliseconds) {
96+
@TruffleBoundary
97+
private DateTime time(long milliseconds) {
11898
return new DateTime(milliseconds, DateTimeZone.UTC);
11999
}
120100

121-
@CompilerDirectives.TruffleBoundary
122-
private DateTime time(long milliseconds, RubyString timeZone) {
101+
@TruffleBoundary
102+
private DateTime localtime(long milliseconds, RubyString timeZone) {
123103
return new DateTime(milliseconds, org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), timeZone.toString()));
124104
}
125105

@@ -160,7 +140,7 @@ public TimeDecomposePrimitiveNode(RubyContext context, SourceSection sourceSecti
160140
super(context, sourceSection);
161141
}
162142

163-
@CompilerDirectives.TruffleBoundary
143+
@TruffleBoundary
164144
@Specialization
165145
public RubyArray timeDecompose(RubyTime time) {
166146
final DateTime dateTime = time.getDateTime();
@@ -203,7 +183,7 @@ public TimeStrftimePrimitiveNode(RubyContext context, SourceSection sourceSectio
203183
super(context, sourceSection);
204184
}
205185

206-
@CompilerDirectives.TruffleBoundary
186+
@TruffleBoundary
207187
@Specialization
208188
public RubyString timeStrftime(RubyTime time, RubyString format) {
209189
final RubyDateFormatter rdf = getContext().getRuntime().getCurrentContext().getRubyDateFormatter();

0 commit comments

Comments
 (0)