|
9 | 9 | */
|
10 | 10 | package org.truffleruby.core.cast;
|
11 | 11 |
|
| 12 | +import com.oracle.truffle.api.CompilerDirectives; |
| 13 | +import com.oracle.truffle.api.dsl.Cached; |
12 | 14 | import org.truffleruby.language.Nil;
|
13 | 15 | import org.truffleruby.language.RubyContextSourceNode;
|
14 | 16 | import org.truffleruby.language.NotProvided;
|
15 | 17 | import org.truffleruby.language.RubyDynamicObject;
|
16 | 18 | import org.truffleruby.language.RubyNode;
|
17 | 19 | import org.truffleruby.language.control.RaiseException;
|
18 | 20 |
|
19 |
| -import com.oracle.truffle.api.CompilerDirectives; |
20 | 21 | import com.oracle.truffle.api.dsl.NodeChild;
|
21 | 22 | import com.oracle.truffle.api.dsl.Specialization;
|
22 | 23 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
| 24 | +import org.truffleruby.language.dispatch.DispatchNode; |
23 | 25 |
|
24 | 26 | @NodeChild(value = "duration", type = RubyNode.class)
|
25 | 27 | public abstract class DurationToMillisecondsNode extends RubyContextSourceNode {
|
26 | 28 |
|
27 |
| - @Child NumericToFloatNode floatCastNode; |
| 29 | + @Child private DispatchNode durationToMilliseconds; |
28 | 30 |
|
29 | 31 | private final ConditionProfile durationLessThanZeroProfile = ConditionProfile.create();
|
30 | 32 | private final boolean acceptsNil;
|
@@ -65,12 +67,17 @@ protected long durationNil(Nil duration) {
|
65 | 67 | }
|
66 | 68 |
|
67 | 69 | @Specialization
|
68 |
| - protected long duration(RubyDynamicObject duration) { |
69 |
| - if (floatCastNode == null) { |
| 70 | + protected Object duration(RubyDynamicObject duration, |
| 71 | + @Cached ToLongNode toLongNode) { |
| 72 | + if (durationToMilliseconds == null) { |
70 | 73 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
71 |
| - floatCastNode = insert(NumericToFloatNodeGen.create()); |
| 74 | + durationToMilliseconds = insert(DispatchNode.create()); |
72 | 75 | }
|
73 |
| - return duration(floatCastNode.executeDouble(duration)); |
| 76 | + |
| 77 | + return toLongNode.execute(durationToMilliseconds.call( |
| 78 | + coreLibrary().truffleKernelOperationsModule, |
| 79 | + "convert_duration_to_milliseconds", |
| 80 | + duration)); |
74 | 81 | }
|
75 | 82 |
|
76 | 83 | private long validate(long durationInMillis) {
|
|
0 commit comments