Skip to content

Commit d6d5d1f

Browse files
committed
---
yaml --- r: 101796 b: refs/heads/master c: d5e0622 h: refs/heads/master v: v3
1 parent 4565e2a commit d6d5d1f

File tree

28 files changed

+346
-58
lines changed

28 files changed

+346
-58
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 68129d299b54806b6aa4ec9f3a0755854db7b491
2+
refs/heads/master: d5e0622f95252e442b909011129336c11ddb0151
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/libarena/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use std::cast::{transmute, transmute_mut, transmute_mut_region};
3333
use std::cast;
3434
use std::cell::{Cell, RefCell};
3535
use std::mem;
36-
use std::cmp;
3736
use std::num;
3837
use std::kinds::marker;
3938
use std::rc::Rc;
@@ -184,7 +183,7 @@ impl Arena {
184183
// Functions for the POD part of the arena
185184
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
186185
// Allocate a new chunk.
187-
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
186+
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
188187
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
189188
self.pod_head =
190189
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -224,7 +223,7 @@ impl Arena {
224223
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
225224
-> (*u8, *u8) {
226225
// Allocate a new chunk.
227-
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
226+
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
228227
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
229228
self.head =
230229
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);

trunk/src/libcollections/bitv.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use std::cmp;
1515
use std::iter::RandomAccessIterator;
1616
use std::iter::{Rev, Enumerate, Repeat, Map, Zip};
17+
use std::num;
1718
use std::ops;
1819
use std::uint;
1920
use std::vec;
@@ -845,7 +846,7 @@ impl MutableSet<uint> for BitvSet {
845846
}
846847
let nbits = self.capacity();
847848
if value >= nbits {
848-
let newsize = cmp::max(value, nbits * 2) / uint::BITS + 1;
849+
let newsize = num::max(value, nbits * 2) / uint::BITS + 1;
849850
assert!(newsize > self.bitv.storage.len());
850851
self.bitv.storage.grow(newsize, &0);
851852
}
@@ -880,7 +881,7 @@ impl BitvSet {
880881
fn commons<'a>(&'a self, other: &'a BitvSet)
881882
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
882883
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
883-
let min = cmp::min(self.bitv.storage.len(), other.bitv.storage.len());
884+
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
884885
self.bitv.storage.slice(0, min).iter().enumerate()
885886
.zip(Repeat::new(&other.bitv.storage))
886887
.map(|((i, &w), o_store)| (i * uint::BITS, w, o_store[i]))

trunk/src/libcollections/ringbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! RingBuf implements the trait Deque. It should be imported with `use
1414
//! extra::container::Deque`.
1515
16-
use std::cmp;
16+
use std::num;
1717
use std::vec;
1818
use std::iter::{Rev, RandomAccessIterator};
1919

@@ -120,7 +120,7 @@ impl<T> RingBuf<T> {
120120
/// Create an empty RingBuf with space for at least `n` elements.
121121
pub fn with_capacity(n: uint) -> RingBuf<T> {
122122
RingBuf{nelts: 0, lo: 0,
123-
elts: vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
123+
elts: vec::from_fn(num::max(MINIMUM_CAPACITY, n), |_| None)}
124124
}
125125

126126
/// Retrieve an element in the RingBuf by index

trunk/src/libextra/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use time::precise_time_ns;
2727
use collections::TreeMap;
2828

2929
use std::clone::Clone;
30-
use std::cmp;
3130
use std::io;
3231
use std::io::File;
3332
use std::io::Writer;
@@ -1004,7 +1003,7 @@ impl MetricMap {
10041003
if delta.abs() <= noise {
10051004
LikelyNoise
10061005
} else {
1007-
let pct = delta.abs() / cmp::max(vold.value, f64::EPSILON) * 100.0;
1006+
let pct = delta.abs() / (vold.value).max(&f64::EPSILON) * 100.0;
10081007
if vold.noise < 0.0 {
10091008
// When 'noise' is negative, it means we want
10101009
// to see deltas that go up over time, and can
@@ -1127,7 +1126,7 @@ impl BenchHarness {
11271126
if self.iterations == 0 {
11281127
0
11291128
} else {
1130-
self.ns_elapsed() / cmp::max(self.iterations, 1)
1129+
self.ns_elapsed() / self.iterations.max(&1)
11311130
}
11321131
}
11331132
@@ -1150,7 +1149,7 @@ impl BenchHarness {
11501149
if self.ns_per_iter() == 0 {
11511150
n = 1_000_000;
11521151
} else {
1153-
n = 1_000_000 / cmp::max(self.ns_per_iter(), 1);
1152+
n = 1_000_000 / self.ns_per_iter().max(&1);
11541153
}
11551154
// if the first run took more than 1ms we don't want to just
11561155
// be left doing 0 iterations on every loop. The unfortunate
@@ -1216,7 +1215,6 @@ impl BenchHarness {
12161215
}
12171216
12181217
pub mod bench {
1219-
use std::cmp;
12201218
use test::{BenchHarness, BenchSamples};
12211219
12221220
pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
@@ -1229,7 +1227,7 @@ pub mod bench {
12291227
12301228
let ns_iter_summ = bs.auto_bench(f);
12311229
1232-
let ns_iter = cmp::max(ns_iter_summ.median as u64, 1);
1230+
let ns_iter = (ns_iter_summ.median as u64).max(&1);
12331231
let iter_s = 1_000_000_000 / ns_iter;
12341232
let mb_s = (bs.bytes * iter_s) / 1_000_000;
12351233

trunk/src/libglob/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#[license = "MIT/ASL2"];
3030

3131
use std::cell::Cell;
32-
use std::{cmp, os, path};
32+
use std::{os, path};
3333
use std::io::fs;
3434
use std::path::is_sep;
3535

@@ -106,7 +106,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
106106
}
107107

108108
let root_len = pat_root.map_or(0u, |p| p.as_vec().len());
109-
let dir_patterns = pattern.slice_from(cmp::min(root_len, pattern.len()))
109+
let dir_patterns = pattern.slice_from(root_len.min(&pattern.len()))
110110
.split_terminator(is_sep).map(|s| Pattern::new(s)).to_owned_vec();
111111

112112
let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec();

trunk/src/libgreen/stack.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ impl StackPool {
138138

139139
pub fn take_stack(&mut self, min_size: uint) -> Stack {
140140
// Ideally this would be a binary search
141-
match self.stacks.iter().position(|s| s.min_size < min_size) {
141+
match self.stacks.iter().position(|s| min_size <= s.min_size) {
142142
Some(idx) => self.stacks.swap_remove(idx),
143-
None => Stack::new(min_size)
143+
None => Stack::new(min_size)
144144
}
145145
}
146146

@@ -156,3 +156,33 @@ extern {
156156
end: *libc::uintptr_t) -> libc::c_uint;
157157
fn rust_valgrind_stack_deregister(id: libc::c_uint);
158158
}
159+
160+
#[cfg(test)]
161+
mod tests {
162+
use super::StackPool;
163+
164+
#[test]
165+
fn stack_pool_caches() {
166+
let mut p = StackPool::new();
167+
let s = p.take_stack(10);
168+
p.give_stack(s);
169+
let s = p.take_stack(4);
170+
assert_eq!(s.min_size, 10);
171+
p.give_stack(s);
172+
let s = p.take_stack(14);
173+
assert_eq!(s.min_size, 14);
174+
p.give_stack(s);
175+
}
176+
177+
#[test]
178+
fn stack_pool_caches_exact() {
179+
let mut p = StackPool::new();
180+
let mut s = p.take_stack(10);
181+
s.valgrind_id = 100;
182+
p.give_stack(s);
183+
184+
let s = p.take_stack(10);
185+
assert_eq!(s.min_size, 10);
186+
assert_eq!(s.valgrind_id, 100);
187+
}
188+
}

trunk/src/libnum/bigint.rs

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ A `BigUint` is represented as an array of `BigDigit`s.
1616
A `BigInt` is a combination of `BigUint` and `Sign`.
1717
*/
1818

19-
use std::cmp;
2019
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
21-
use std::num::{Zero, One, ToStrRadix, FromStrRadix};
20+
use std::num;
21+
use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
2222
use std::num::{Bitwise, ToPrimitive, FromPrimitive};
2323
use std::rand::Rng;
2424
use std::str;
@@ -133,9 +133,27 @@ impl FromStr for BigUint {
133133

134134
impl Num for BigUint {}
135135

136+
impl Orderable for BigUint {
137+
#[inline]
138+
fn min(&self, other: &BigUint) -> BigUint {
139+
if self < other { self.clone() } else { other.clone() }
140+
}
141+
142+
#[inline]
143+
fn max(&self, other: &BigUint) -> BigUint {
144+
if self > other { self.clone() } else { other.clone() }
145+
}
146+
147+
#[inline]
148+
fn clamp(&self, mn: &BigUint, mx: &BigUint) -> BigUint {
149+
if self > mx { mx.clone() } else
150+
if self < mn { mn.clone() } else { self.clone() }
151+
}
152+
}
153+
136154
impl BitAnd<BigUint, BigUint> for BigUint {
137155
fn bitand(&self, other: &BigUint) -> BigUint {
138-
let new_len = cmp::min(self.data.len(), other.data.len());
156+
let new_len = num::min(self.data.len(), other.data.len());
139157
let anded = vec::from_fn(new_len, |i| {
140158
// i will never be less than the size of either data vector
141159
let ai = self.data[i];
@@ -148,7 +166,7 @@ impl BitAnd<BigUint, BigUint> for BigUint {
148166

149167
impl BitOr<BigUint, BigUint> for BigUint {
150168
fn bitor(&self, other: &BigUint) -> BigUint {
151-
let new_len = cmp::max(self.data.len(), other.data.len());
169+
let new_len = num::max(self.data.len(), other.data.len());
152170
let ored = vec::from_fn(new_len, |i| {
153171
let ai = if i < self.data.len() { self.data[i] } else { 0 };
154172
let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -160,7 +178,7 @@ impl BitOr<BigUint, BigUint> for BigUint {
160178

161179
impl BitXor<BigUint, BigUint> for BigUint {
162180
fn bitxor(&self, other: &BigUint) -> BigUint {
163-
let new_len = cmp::max(self.data.len(), other.data.len());
181+
let new_len = num::max(self.data.len(), other.data.len());
164182
let xored = vec::from_fn(new_len, |i| {
165183
let ai = if i < self.data.len() { self.data[i] } else { 0 };
166184
let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -205,7 +223,7 @@ impl Unsigned for BigUint {}
205223

206224
impl Add<BigUint, BigUint> for BigUint {
207225
fn add(&self, other: &BigUint) -> BigUint {
208-
let new_len = cmp::max(self.data.len(), other.data.len());
226+
let new_len = num::max(self.data.len(), other.data.len());
209227

210228
let mut carry = 0;
211229
let mut sum = vec::from_fn(new_len, |i| {
@@ -224,7 +242,7 @@ impl Add<BigUint, BigUint> for BigUint {
224242

225243
impl Sub<BigUint, BigUint> for BigUint {
226244
fn sub(&self, other: &BigUint) -> BigUint {
227-
let new_len = cmp::max(self.data.len(), other.data.len());
245+
let new_len = num::max(self.data.len(), other.data.len());
228246

229247
let mut borrow = 0;
230248
let diff = vec::from_fn(new_len, |i| {
@@ -260,7 +278,7 @@ impl Mul<BigUint, BigUint> for BigUint {
260278
// = a1*b1 * base^2 +
261279
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
262280
// a0*b0
263-
let half_len = cmp::max(s_len, o_len) / 2;
281+
let half_len = num::max(s_len, o_len) / 2;
264282
let (sHi, sLo) = cut_at(self, half_len);
265283
let (oHi, oLo) = cut_at(other, half_len);
266284

@@ -297,7 +315,7 @@ impl Mul<BigUint, BigUint> for BigUint {
297315

298316
#[inline]
299317
fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
300-
let mid = cmp::min(a.data.len(), n);
318+
let mid = num::min(a.data.len(), n);
301319
return (BigUint::from_slice(a.data.slice(mid, a.data.len())),
302320
BigUint::from_slice(a.data.slice(0, mid)));
303321
}
@@ -702,7 +720,7 @@ impl BigUint {
702720
let mut n: BigUint = Zero::zero();
703721
let mut power: BigUint = One::one();
704722
loop {
705-
let start = cmp::max(end, unit_len) - unit_len;
723+
let start = num::max(end, unit_len) - unit_len;
706724
match uint::parse_bytes(buf.slice(start, end), radix) {
707725
Some(d) => {
708726
let d: Option<BigUint> = FromPrimitive::from_uint(d);
@@ -923,6 +941,24 @@ impl FromStr for BigInt {
923941

924942
impl Num for BigInt {}
925943

944+
impl Orderable for BigInt {
945+
#[inline]
946+
fn min(&self, other: &BigInt) -> BigInt {
947+
if self < other { self.clone() } else { other.clone() }
948+
}
949+
950+
#[inline]
951+
fn max(&self, other: &BigInt) -> BigInt {
952+
if self > other { self.clone() } else { other.clone() }
953+
}
954+
955+
#[inline]
956+
fn clamp(&self, mn: &BigInt, mx: &BigInt) -> BigInt {
957+
if self > mx { mx.clone() } else
958+
if self < mn { mn.clone() } else { self.clone() }
959+
}
960+
}
961+
926962
impl Shl<uint, BigInt> for BigInt {
927963
#[inline]
928964
fn shl(&self, rhs: &uint) -> BigInt {

trunk/src/libnum/rational.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ cmp_impl!(impl TotalEq, equals)
160160
cmp_impl!(impl Ord, lt, gt, le, ge)
161161
cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering)
162162

163+
impl<T: Clone + Integer + Ord> Orderable for Ratio<T> {
164+
#[inline]
165+
fn min(&self, other: &Ratio<T>) -> Ratio<T> {
166+
if *self < *other { self.clone() } else { other.clone() }
167+
}
168+
169+
#[inline]
170+
fn max(&self, other: &Ratio<T>) -> Ratio<T> {
171+
if *self > *other { self.clone() } else { other.clone() }
172+
}
173+
174+
#[inline]
175+
fn clamp(&self, mn: &Ratio<T>, mx: &Ratio<T>) -> Ratio<T> {
176+
if *self > *mx { mx.clone()} else
177+
if *self < *mn { mn.clone() } else { self.clone() }
178+
}
179+
}
180+
181+
163182
/* Arithmetic */
164183
// a/b * c/d = (a*c)/(b*d)
165184
impl<T: Clone + Integer + Ord>

trunk/src/librustc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ use middle::lint;
4646

4747
use d = driver::driver;
4848

49-
use std::cmp;
5049
use std::io;
50+
use std::num;
5151
use std::os;
5252
use std::str;
5353
use std::task;
@@ -164,7 +164,7 @@ Available lint options:
164164

165165
let mut max_key = 0;
166166
for &(_, name) in lint_dict.iter() {
167-
max_key = cmp::max(name.len(), max_key);
167+
max_key = num::max(name.len(), max_key);
168168
}
169169
fn padded(max: uint, s: &str) -> ~str {
170170
" ".repeat(max - s.len()) + s

trunk/src/librustc/metadata/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use syntax::attr::AttrMetaMethods;
2626

2727
use std::c_str::ToCStr;
2828
use std::cast;
29-
use std::cmp;
3029
use std::io;
30+
use std::num;
3131
use std::option;
3232
use std::os::consts::{macos, freebsd, linux, android, win32};
3333
use std::str;
@@ -331,7 +331,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Option<MetadataBlob> {
331331
let vlen = encoder::metadata_encoding_version.len();
332332
debug!("checking {} bytes of metadata-version stamp",
333333
vlen);
334-
let minsz = cmp::min(vlen, csz);
334+
let minsz = num::min(vlen, csz);
335335
let mut version_ok = false;
336336
vec::raw::buf_as_slice(cvbuf, minsz, |buf0| {
337337
version_ok = (buf0 ==

0 commit comments

Comments
 (0)