Skip to content

Commit 68129d2

Browse files
committed
auto merge of #12061 : pongad/rust/delorderable, r=cmr
#12057
2 parents 89b1686 + bf1464c commit 68129d2

26 files changed

+55
-313
lines changed

src/libarena/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ 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;
3637
use std::num;
3738
use std::kinds::marker;
3839
use std::rc::Rc;
@@ -183,7 +184,7 @@ impl Arena {
183184
// Functions for the POD part of the arena
184185
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
185186
// Allocate a new chunk.
186-
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
187+
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
187188
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
188189
self.pod_head =
189190
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -223,7 +224,7 @@ impl Arena {
223224
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
224225
-> (*u8, *u8) {
225226
// Allocate a new chunk.
226-
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
227+
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
227228
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
228229
self.head =
229230
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);

src/libcollections/bitv.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use std::cmp;
1515
use std::iter::RandomAccessIterator;
1616
use std::iter::{Rev, Enumerate, Repeat, Map, Zip};
17-
use std::num;
1817
use std::ops;
1918
use std::uint;
2019
use std::vec;
@@ -846,7 +845,7 @@ impl MutableSet<uint> for BitvSet {
846845
}
847846
let nbits = self.capacity();
848847
if value >= nbits {
849-
let newsize = num::max(value, nbits * 2) / uint::BITS + 1;
848+
let newsize = cmp::max(value, nbits * 2) / uint::BITS + 1;
850849
assert!(newsize > self.bitv.storage.len());
851850
self.bitv.storage.grow(newsize, &0);
852851
}
@@ -881,7 +880,7 @@ impl BitvSet {
881880
fn commons<'a>(&'a self, other: &'a BitvSet)
882881
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
883882
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
884-
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
883+
let min = cmp::min(self.bitv.storage.len(), other.bitv.storage.len());
885884
self.bitv.storage.slice(0, min).iter().enumerate()
886885
.zip(Repeat::new(&other.bitv.storage))
887886
.map(|((i, &w), o_store)| (i * uint::BITS, w, o_store[i]))

src/libcollections/ringbuf.rs

+2-2
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::num;
16+
use std::cmp;
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(num::max(MINIMUM_CAPACITY, n), |_| None)}
123+
elts: vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
124124
}
125125

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

src/libextra/test.rs

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

2929
use std::clone::Clone;
30+
use std::cmp;
3031
use std::io;
3132
use std::io::File;
3233
use std::io::Writer;
@@ -1003,7 +1004,7 @@ impl MetricMap {
10031004
if delta.abs() <= noise {
10041005
LikelyNoise
10051006
} else {
1006-
let pct = delta.abs() / (vold.value).max(&f64::EPSILON) * 100.0;
1007+
let pct = delta.abs() / cmp::max(vold.value, f64::EPSILON) * 100.0;
10071008
if vold.noise < 0.0 {
10081009
// When 'noise' is negative, it means we want
10091010
// to see deltas that go up over time, and can
@@ -1126,7 +1127,7 @@ impl BenchHarness {
11261127
if self.iterations == 0 {
11271128
0
11281129
} else {
1129-
self.ns_elapsed() / self.iterations.max(&1)
1130+
self.ns_elapsed() / cmp::max(self.iterations, 1)
11301131
}
11311132
}
11321133
@@ -1149,7 +1150,7 @@ impl BenchHarness {
11491150
if self.ns_per_iter() == 0 {
11501151
n = 1_000_000;
11511152
} else {
1152-
n = 1_000_000 / self.ns_per_iter().max(&1);
1153+
n = 1_000_000 / cmp::max(self.ns_per_iter(), 1);
11531154
}
11541155
// if the first run took more than 1ms we don't want to just
11551156
// be left doing 0 iterations on every loop. The unfortunate
@@ -1215,6 +1216,7 @@ impl BenchHarness {
12151216
}
12161217
12171218
pub mod bench {
1219+
use std::cmp;
12181220
use test::{BenchHarness, BenchSamples};
12191221
12201222
pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
@@ -1227,7 +1229,7 @@ pub mod bench {
12271229
12281230
let ns_iter_summ = bs.auto_bench(f);
12291231
1230-
let ns_iter = (ns_iter_summ.median as u64).max(&1);
1232+
let ns_iter = cmp::max(ns_iter_summ.median as u64, 1);
12311233
let iter_s = 1_000_000_000 / ns_iter;
12321234
let mb_s = (bs.bytes * iter_s) / 1_000_000;
12331235

src/libglob/lib.rs

+2-2
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::{os, path};
32+
use std::{cmp, 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(root_len.min(&pattern.len()))
109+
let dir_patterns = pattern.slice_from(cmp::min(root_len, 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();

src/libnum/bigint.rs

+10-46
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;
1920
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
20-
use std::num;
21-
use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
21+
use std::num::{Zero, One, ToStrRadix, FromStrRadix};
2222
use std::num::{Bitwise, ToPrimitive, FromPrimitive};
2323
use std::rand::Rng;
2424
use std::str;
@@ -133,27 +133,9 @@ 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-
154136
impl BitAnd<BigUint, BigUint> for BigUint {
155137
fn bitand(&self, other: &BigUint) -> BigUint {
156-
let new_len = num::min(self.data.len(), other.data.len());
138+
let new_len = cmp::min(self.data.len(), other.data.len());
157139
let anded = vec::from_fn(new_len, |i| {
158140
// i will never be less than the size of either data vector
159141
let ai = self.data[i];
@@ -166,7 +148,7 @@ impl BitAnd<BigUint, BigUint> for BigUint {
166148

167149
impl BitOr<BigUint, BigUint> for BigUint {
168150
fn bitor(&self, other: &BigUint) -> BigUint {
169-
let new_len = num::max(self.data.len(), other.data.len());
151+
let new_len = cmp::max(self.data.len(), other.data.len());
170152
let ored = vec::from_fn(new_len, |i| {
171153
let ai = if i < self.data.len() { self.data[i] } else { 0 };
172154
let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -178,7 +160,7 @@ impl BitOr<BigUint, BigUint> for BigUint {
178160

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

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

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

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

247229
let mut borrow = 0;
248230
let diff = vec::from_fn(new_len, |i| {
@@ -278,7 +260,7 @@ impl Mul<BigUint, BigUint> for BigUint {
278260
// = a1*b1 * base^2 +
279261
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
280262
// a0*b0
281-
let half_len = num::max(s_len, o_len) / 2;
263+
let half_len = cmp::max(s_len, o_len) / 2;
282264
let (sHi, sLo) = cut_at(self, half_len);
283265
let (oHi, oLo) = cut_at(other, half_len);
284266

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

316298
#[inline]
317299
fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
318-
let mid = num::min(a.data.len(), n);
300+
let mid = cmp::min(a.data.len(), n);
319301
return (BigUint::from_slice(a.data.slice(mid, a.data.len())),
320302
BigUint::from_slice(a.data.slice(0, mid)));
321303
}
@@ -720,7 +702,7 @@ impl BigUint {
720702
let mut n: BigUint = Zero::zero();
721703
let mut power: BigUint = One::one();
722704
loop {
723-
let start = num::max(end, unit_len) - unit_len;
705+
let start = cmp::max(end, unit_len) - unit_len;
724706
match uint::parse_bytes(buf.slice(start, end), radix) {
725707
Some(d) => {
726708
let d: Option<BigUint> = FromPrimitive::from_uint(d);
@@ -941,24 +923,6 @@ impl FromStr for BigInt {
941923

942924
impl Num for BigInt {}
943925

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-
962926
impl Shl<uint, BigInt> for BigInt {
963927
#[inline]
964928
fn shl(&self, rhs: &uint) -> BigInt {

src/libnum/rational.rs

-19
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,6 @@ 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-
182163
/* Arithmetic */
183164
// a/b * c/d = (a*c)/(b*d)
184165
impl<T: Clone + Integer + Ord>

src/librustc/lib.rs

+2-2
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;
4950
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 = num::max(name.len(), max_key);
167+
max_key = cmp::max(name.len(), max_key);
168168
}
169169
fn padded(max: uint, s: &str) -> ~str {
170170
" ".repeat(max - s.len()) + s

src/librustc/metadata/loader.rs

+2-2
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;
2930
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 = num::min(vlen, csz);
334+
let minsz = cmp::min(vlen, csz);
335335
let mut version_ok = false;
336336
vec::raw::buf_as_slice(cvbuf, minsz, |buf0| {
337337
version_ok = (buf0 ==

src/librustc/middle/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use middle::typeck::method_map;
1818
use middle::moves;
1919
use util::ppaux::ty_to_str;
2020

21+
use std::cmp;
2122
use std::iter;
22-
use std::num;
2323
use std::vec;
2424
use syntax::ast::*;
2525
use syntax::ast_util::{unguarded_pat, walk_pat};
@@ -286,7 +286,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
286286
let max_len = m.rev_iter().fold(0, |max_len, r| {
287287
match r[0].node {
288288
PatVec(ref before, _, ref after) => {
289-
num::max(before.len() + after.len(), max_len)
289+
cmp::max(before.len() + after.len(), max_len)
290290
}
291291
_ => max_len
292292
}

src/librustc/middle/trans/cabi_arm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use middle::trans::context::CrateContext;
1717

1818
use middle::trans::type_::Type;
1919

20-
use std::num;
20+
use std::cmp;
2121
use std::option::{None, Some};
2222

2323
fn align_up_to(off: uint, a: uint) -> uint {
@@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
4444
1
4545
} else {
4646
let str_tys = ty.field_types();
47-
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
47+
str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
4848
}
4949
}
5050
Array => {

src/librustc/middle/trans/cabi_mips.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#[allow(non_uppercase_pattern_statics)];
1212

1313
use std::libc::c_uint;
14-
use std::num;
14+
use std::cmp;
1515
use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
1616
use lib::llvm::StructRetAttribute;
1717
use middle::trans::context::CrateContext;
@@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
4444
1
4545
} else {
4646
let str_tys = ty.field_types();
47-
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
47+
str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
4848
}
4949
}
5050
Array => {
@@ -98,7 +98,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> ArgType {
9898
let size = ty_size(ty) * 8;
9999
let mut align = ty_align(ty);
100100

101-
align = num::min(num::max(align, 4), 8);
101+
align = cmp::min(cmp::max(align, 4), 8);
102102
*offset = align_up_to(*offset, align);
103103
*offset += align_up_to(size, align * 8) / 8;
104104

0 commit comments

Comments
 (0)