Skip to content

Commit c116d12

Browse files
committed
Make Process.clock_gettime(Process::CLOCK_MONOTONIC) simpler
1 parent e90492d commit c116d12

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/main/java/org/truffleruby/core/ProcessNodes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public abstract class ProcessNodes {
2727
@Primitive(name = "process_time_nanotime")
2828
public abstract static class ProcessTimeNanoTimeNode extends PrimitiveArrayArgumentsNode {
2929

30-
@TruffleBoundary
3130
@Specialization
3231
protected long nanoTime() {
3332
return System.nanoTime();

src/main/ruby/truffleruby/core/process.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ def self.clock_gettime(id, unit=:float_second)
156156
end
157157

158158
case id
159-
when CLOCK_REALTIME
160-
time = Primitive.process_time_instant
161159
when CLOCK_MONOTONIC
162160
time = Primitive.process_time_nanotime
161+
when CLOCK_REALTIME
162+
time = Primitive.process_time_instant
163163
else
164164
time = Truffle::POSIX.truffleposix_clock_gettime(id)
165165
Errno.handle if time == 0
@@ -170,20 +170,20 @@ def self.clock_gettime(id, unit=:float_second)
170170

171171
def self.nanoseconds_to_unit(nanoseconds, unit)
172172
case unit
173-
when :nanosecond
174-
nanoseconds
175-
when :microsecond
176-
nanoseconds / 1_000
177-
when :millisecond
178-
nanoseconds / 1_000_000
179-
when :second
180-
nanoseconds / 1_000_000_000
173+
when :float_second, nil
174+
nanoseconds / 1e9
181175
when :float_microsecond
182176
nanoseconds / 1e3
183177
when :float_millisecond
184178
nanoseconds / 1e6
185-
when :float_second, nil
186-
nanoseconds / 1e9
179+
when :second
180+
nanoseconds / 1_000_000_000
181+
when :millisecond
182+
nanoseconds / 1_000_000
183+
when :microsecond
184+
nanoseconds / 1_000
185+
when :nanosecond
186+
nanoseconds
187187
else
188188
raise ArgumentError, "unexpected unit: #{unit}"
189189
end

0 commit comments

Comments
 (0)