Skip to content

Commit 588e407

Browse files
committed
---
yaml --- r: 154299 b: refs/heads/try2 c: 6cb2093 h: refs/heads/master i: 154297: 090bf3f 154295: 9d0d86c v: v3
1 parent 68556e4 commit 588e407

File tree

3 files changed

+329
-101
lines changed

3 files changed

+329
-101
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 18f75a9197a5b535f9804901bfefbaffe373d689
8+
refs/heads/try2: 6cb2093f7496a2539e343677b6f7f5dd2fa5f091
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/io/timer.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use time::Duration;
2222
use io::{IoResult, IoError};
2323
use kinds::Send;
2424
use boxed::Box;
25-
use num::{CheckedMul, CheckedAdd};
2625
use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback};
2726

2827
/// A synchronous timer object
@@ -71,31 +70,16 @@ pub struct Timer {
7170

7271
struct TimerCallback { tx: Sender<()> }
7372

74-
#[allow(missing_doc)]
75-
trait DurationExtension {
76-
fn in_ms(&self) -> u64;
77-
}
78-
79-
impl DurationExtension for Duration {
80-
fn in_ms(&self) -> u64 {
81-
if self.ndays() < 0 { fail!("negative duration") }
82-
let nanos = self.nnanoseconds() as u64;
83-
let secs = self.nseconds() as u64;
84-
let days = self.ndays() as u64;
85-
let nanos_in_ms = nanos / 1000;
86-
let secs_in_ms = secs.checked_mul(&1000).expect("overflow");
87-
let ms_per_day = 24 * 60 * 60 * 1000; // hours/day * min/hour * sec/min * ms/sec
88-
let days_in_ms = days.checked_mul(&ms_per_day).expect("overflow");
89-
let result = nanos_in_ms;
90-
let result = result.checked_add(&secs_in_ms).expect("overflow");
91-
let result = result.checked_add(&(days_in_ms as u64)).expect("overflow");
92-
return result;
93-
}
73+
fn in_ms(d: Duration) -> u64 {
74+
// FIXME: Do we really want to fail on negative duration?
75+
let ms = d.num_milliseconds();
76+
if ms < 0 { fail!("negative duration") }
77+
return ms as u64;
9478
}
9579

9680
/// Sleep the current task for the specified duration.
9781
pub fn sleep(duration: Duration) {
98-
sleep_ms(duration.in_ms())
82+
sleep_ms(in_ms(duration))
9983
}
10084

10185
/// Sleep the current task for `msecs` milliseconds.
@@ -121,7 +105,7 @@ impl Timer {
121105
/// Note that this function will cause any other receivers for this timer to
122106
/// be invalidated (the other end will be closed).
123107
pub fn sleep(&mut self, duration: Duration) {
124-
self.obj.sleep(duration.in_ms());
108+
self.obj.sleep(in_ms(duration));
125109
}
126110

127111
/// Blocks the current task for `msecs` milliseconds.
@@ -145,7 +129,7 @@ impl Timer {
145129
/// fail.
146130
pub fn oneshot(&mut self, duration: Duration) -> Receiver<()> {
147131
let (tx, rx) = channel();
148-
self.obj.oneshot(duration.in_ms(), box TimerCallback { tx: tx });
132+
self.obj.oneshot(in_ms(duration), box TimerCallback { tx: tx });
149133
return rx
150134
}
151135

@@ -204,7 +188,7 @@ impl Timer {
204188
/// fail.
205189
pub fn periodic(&mut self, duration: Duration) -> Receiver<()> {
206190
let (tx, rx) = channel();
207-
self.obj.period(duration.in_ms(), box TimerCallback { tx: tx });
191+
self.obj.period(in_ms(duration), box TimerCallback { tx: tx });
208192
return rx
209193
}
210194

0 commit comments

Comments
 (0)