Skip to content

Commit 053f8d0

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163433 b: refs/heads/snap-stage3 c: 9126a24 h: refs/heads/master i: 163431: 5565092 v: v3
1 parent e25aa5f commit 053f8d0

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 32168faf9f7a9e634647b86c1a671ae68dbe9c9d
4+
refs/heads/snap-stage3: 9126a24e423a8339230f1dde7e36f79faaeaa9d3
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libstd/time/duration.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ impl Neg<Duration> for Duration {
276276
}
277277
}
278278

279+
// NOTE(stage0): Remove impl after a snapshot
280+
#[cfg(stage0)]
279281
impl Add<Duration,Duration> for Duration {
280282
fn add(&self, rhs: &Duration) -> Duration {
281283
let mut secs = self.secs + rhs.secs;
@@ -288,6 +290,21 @@ impl Add<Duration,Duration> for Duration {
288290
}
289291
}
290292

293+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
294+
impl Add<Duration, Duration> for Duration {
295+
fn add(self, rhs: Duration) -> Duration {
296+
let mut secs = self.secs + rhs.secs;
297+
let mut nanos = self.nanos + rhs.nanos;
298+
if nanos >= NANOS_PER_SEC {
299+
nanos -= NANOS_PER_SEC;
300+
secs += 1;
301+
}
302+
Duration { secs: secs, nanos: nanos }
303+
}
304+
}
305+
306+
// NOTE(stage0): Remove impl after a snapshot
307+
#[cfg(stage0)]
291308
impl Sub<Duration,Duration> for Duration {
292309
fn sub(&self, rhs: &Duration) -> Duration {
293310
let mut secs = self.secs - rhs.secs;
@@ -300,6 +317,21 @@ impl Sub<Duration,Duration> for Duration {
300317
}
301318
}
302319

320+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
321+
impl Sub<Duration, Duration> for Duration {
322+
fn sub(self, rhs: Duration) -> Duration {
323+
let mut secs = self.secs - rhs.secs;
324+
let mut nanos = self.nanos - rhs.nanos;
325+
if nanos < 0 {
326+
nanos += NANOS_PER_SEC;
327+
secs -= 1;
328+
}
329+
Duration { secs: secs, nanos: nanos }
330+
}
331+
}
332+
333+
// NOTE(stage0): Remove impl after a snapshot
334+
#[cfg(stage0)]
303335
impl Mul<i32,Duration> for Duration {
304336
fn mul(&self, rhs: &i32) -> Duration {
305337
// Multiply nanoseconds as i64, because it cannot overflow that way.
@@ -310,6 +342,19 @@ impl Mul<i32,Duration> for Duration {
310342
}
311343
}
312344

345+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
346+
impl Mul<i32, Duration> for Duration {
347+
fn mul(self, rhs: i32) -> Duration {
348+
// Multiply nanoseconds as i64, because it cannot overflow that way.
349+
let total_nanos = self.nanos as i64 * rhs as i64;
350+
let (extra_secs, nanos) = div_mod_floor_64(total_nanos, NANOS_PER_SEC as i64);
351+
let secs = self.secs * rhs as i64 + extra_secs;
352+
Duration { secs: secs, nanos: nanos as i32 }
353+
}
354+
}
355+
356+
// NOTE(stage0): Remove impl after a snapshot
357+
#[cfg(stage0)]
313358
impl Div<i32,Duration> for Duration {
314359
fn div(&self, rhs: &i32) -> Duration {
315360
let mut secs = self.secs / *rhs as i64;
@@ -328,6 +373,25 @@ impl Div<i32,Duration> for Duration {
328373
}
329374
}
330375

376+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
377+
impl Div<i32, Duration> for Duration {
378+
fn div(self, rhs: i32) -> Duration {
379+
let mut secs = self.secs / rhs as i64;
380+
let carry = self.secs - secs * rhs as i64;
381+
let extra_nanos = carry * NANOS_PER_SEC as i64 / rhs as i64;
382+
let mut nanos = self.nanos / rhs + extra_nanos as i32;
383+
if nanos >= NANOS_PER_SEC {
384+
nanos -= NANOS_PER_SEC;
385+
secs += 1;
386+
}
387+
if nanos < 0 {
388+
nanos += NANOS_PER_SEC;
389+
secs -= 1;
390+
}
391+
Duration { secs: secs, nanos: nanos }
392+
}
393+
}
394+
331395
impl fmt::Show for Duration {
332396
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
333397
// technically speaking, negative duration is not valid ISO 8601,

0 commit comments

Comments
 (0)