Skip to content

Commit 3ad03a5

Browse files
committed
[Truffle] Only keep a single specialization for the time_s_from_array primitive.
1 parent 0a256b2 commit 3ad03a5

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

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

+12-57
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.oracle.truffle.api.dsl.Specialization;
1414
import com.oracle.truffle.api.frame.VirtualFrame;
1515
import com.oracle.truffle.api.source.SourceSection;
16+
1617
import org.joda.time.DateTime;
1718
import org.joda.time.DateTimeZone;
1819
import org.jruby.truffle.nodes.time.ReadTimeZoneNode;
@@ -212,42 +213,29 @@ public RubyString timeStrftime(RubyTime time, RubyString format) {
212213

213214
}
214215

215-
@RubiniusPrimitive(name = "time_s_from_array", needsSelf = true)
216+
@RubiniusPrimitive(name = "time_s_from_array", needsSelf = true, lowerFixnumParameters = { 0 /*sec*/, 6 /*nsec*/, 7 /*isdst*/})
216217
public static abstract class TimeSFromArrayPrimitiveNode extends RubiniusPrimitiveNode {
217218

218219
public TimeSFromArrayPrimitiveNode(RubyContext context, SourceSection sourceSection) {
219220
super(context, sourceSection);
220221
}
221222

222-
@Specialization(guards = {"isNil(sec)", "isNil(nsec)"})
223-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, Object sec, int min, int hour, int mday, int month, int year,
224-
Object nsec, int isdst, boolean fromutc, Object utcoffset) {
225-
return timeSFromArray(frame, timeClass, 0, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset);
223+
@Specialization
224+
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year,
225+
int nsec, int isdst, boolean fromutc, Object utcoffset) {
226+
return buildTime(frame, timeClass, sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset);
226227
}
227228

228-
@Specialization(guards = "isNil(nsec)")
229-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year,
229+
@Specialization(guards = "!isInteger(sec) || !isInteger(nsec)")
230+
public RubyTime timeSFromArrayFallback(VirtualFrame frame, RubyClass timeClass, Object sec, int min, int hour, int mday, int month, int year,
230231
Object nsec, int isdst, boolean fromutc, Object utcoffset) {
231-
return buildTime(frame, timeClass, sec, min, hour, mday, month, year, 0, isdst, fromutc, utcoffset);
232+
return null; // Primitive failure
232233
}
233234

234-
@Specialization
235-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, long sec, int min, int hour, int mday, int month, int year,
235+
private RubyTime buildTime(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year,
236236
int nsec, int isdst, boolean fromutc, Object utcoffset) {
237-
// TODO CS 15-Feb-15 that cast
238-
return buildTime(frame, timeClass, (int) sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset);
239-
}
237+
CompilerDirectives.transferToInterpreter();
240238

241-
@Specialization
242-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year,
243-
long nsec, int isdst, boolean fromutc, Object utcoffset) {
244-
// TODO CS 15-Feb-15 that cast
245-
return buildTime(frame, timeClass, sec, min, hour, mday, month, year, (int) nsec, isdst, fromutc, utcoffset);
246-
}
247-
248-
@Specialization
249-
public RubyTime buildTime(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year,
250-
int nsec, int isdst, boolean fromutc, Object utcoffset) {
251239
if (sec < 0 || sec > 59 ||
252240
min < 0 || min > 59 ||
253241
hour < 0 || hour > 23 ||
@@ -281,40 +269,7 @@ public RubyTime buildTime(VirtualFrame frame, RubyClass timeClass, int sec, int
281269
}
282270
}
283271

284-
@Specialization(guards = "isNil(nsec)")
285-
public RubyTime timeSFromArray(RubyClass timeClass, RubyBasicObject sec, int min, int hour, int mday, int month, int year,
286-
Object nsec, int isdst, boolean fromutc, Object utcoffset) {
287-
return null;
288-
}
289-
290-
@Specialization
291-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year,
292-
long nsec, int isdst, boolean fromutc, Object utcoffset) {
293-
return timeSFromArray(frame, timeClass, sec, min, hour, mday, month, year, (int) nsec, isdst, fromutc, utcoffset);
294-
}
295-
296-
@Specialization
297-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year,
298-
int nsec, long isdst, boolean fromutc, Object utcoffset) {
299-
return timeSFromArray(frame, timeClass, sec, min, hour, mday, month, year, nsec, (int) isdst, fromutc, utcoffset);
300-
}
301-
302-
@Specialization(guards = "isNil(nsec)")
303-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year,
304-
Object nsec, int isdst, boolean fromutc, Object utcoffset) {
305-
final int secondsWhole = (int) sec;
306-
final int nanosecondsFractional = (int) ((sec * 1_000_000_000) - (secondsWhole * 1_000_000_000));
307-
return buildTime(frame, timeClass, secondsWhole, min, hour, mday, month, year, nanosecondsFractional, isdst, fromutc, utcoffset);
308-
}
309-
310-
@Specialization
311-
public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year,
312-
int nsec, int isdst, boolean fromutc, Object utcoffset) {
313-
final int secondsWhole = (int) sec;
314-
return buildTime(frame, timeClass, secondsWhole, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset);
315-
}
316-
317-
private int cast(Object value) {
272+
private static int cast(Object value) {
318273
if (value instanceof Integer) {
319274
return (int) value;
320275
} else if (value instanceof Long) {

0 commit comments

Comments
 (0)