提交 c0c8d3aa 编写于 作者: B Brian Anderson

core: Demode int/uint mods

上级 ee2ce036
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
import T = inst::T;
import cmp::{Eq, Ord};
import num::from_int;
......@@ -21,8 +25,8 @@
const min_value: T = (-1 as T) << (bits - 1);
const max_value: T = min_value - 1 as T;
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }
pure fn min(x: &T, y: &T) -> T { if *x < *y { *x } else { *y } }
pure fn max(x: &T, y: &T) -> T { if *x > *y { *x } else { *y } }
pure fn add(x: &T, y: &T) -> T { *x + *y }
pure fn sub(x: &T, y: &T) -> T { *x - *y }
......@@ -155,7 +159,7 @@ fn parse_buf(buf: ~[u8], radix: uint) -> Option<T> {
}
/// Parse a string to an int
fn from_str(s: ~str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
fn from_str(s: &str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
/// Convert to a string in a given base
fn to_str(n: T, radix: uint) -> ~str {
......@@ -235,7 +239,7 @@ fn test_to_str() {
#[test]
fn test_interfaces() {
fn test<U:num::Num>(ten: U) {
fn test<U:num::Num>(+ten: U) {
assert (ten.to_int() == 10);
let two: U = from_int(2);
......
......@@ -284,7 +284,7 @@ fn file_reader(path: &Path) -> Result<Reader, ~str> {
impl ByteBuf: Reader {
fn read(buf: &[mut u8], len: uint) -> uint {
let count = uint::min(len, self.buf.len() - self.pos);
let count = uint::min(&len, &(self.buf.len() - self.pos));
vec::u8::memcpy(buf,
vec::const_view(self.buf, self.pos, self.buf.len()),
......
......@@ -676,7 +676,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
let a_len = a.len();
let b_len = b.len();
if a_len != b_len { return false; }
let mut end = uint::min(a_len, b_len);
let mut end = uint::min(&a_len, &b_len);
let mut i = 0u;
while i < end {
......
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
import T = inst::T;
import cmp::{Eq, Ord};
......@@ -20,8 +24,8 @@
const min_value: T = 0 as T;
const max_value: T = 0 as T - 1 as T;
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }
pure fn min(x: &T, y: &T) -> T { if *x < *y { *x } else { *y } }
pure fn max(x: &T, y: &T) -> T { if *x > *y { *x } else { *y } }
pure fn add(x: &T, y: &T) -> T { *x + *y }
pure fn sub(x: &T, y: &T) -> T { *x - *y }
......@@ -138,10 +142,10 @@ fn parse_buf(buf: &[const u8], radix: uint) -> Option<T> {
}
/// Parse a string to an int
fn from_str(s: ~str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
fn from_str(s: &str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
/// Parse a string as an unsigned integer.
fn from_str_radix(buf: ~str, radix: u64) -> Option<u64> {
fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
if str::len(buf) == 0u { return None; }
let mut i = str::len(buf) - 1u;
let mut power = 1u64, n = 0u64;
......
......@@ -1430,7 +1430,7 @@ impl<T: Eq> @[T]: Eq {
pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
let (a_len, b_len) = (a.len(), b.len());
let mut end = uint::min(a_len, b_len);
let mut end = uint::min(&a_len, &b_len);
let mut i = 0;
while i < end {
......@@ -1821,7 +1821,7 @@ mod u8 {
pure fn cmp(a: &~[u8], b: &~[u8]) -> int {
let a_len = len(*a);
let b_len = len(*b);
let n = uint::min(a_len, b_len) as libc::size_t;
let n = uint::min(&a_len, &b_len) as libc::size_t;
let r = unsafe {
libc::memcmp(unsafe::to_ptr(*a) as *libc::c_void,
unsafe::to_ptr(*b) as *libc::c_void, n) as int
......
......@@ -135,7 +135,7 @@ impl &Arena {
fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.pod_head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
let new_min_chunk_size = uint::max(&n_bytes, &chunk_size);
self.chunks = @cons(copy self.pod_head, self.chunks);
self.pod_head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
......@@ -177,7 +177,7 @@ fn alloc_pod<T>(op: fn() -> T) -> &self/T {
fn alloc_nonpod_grow(n_bytes: uint, align: uint) -> (*u8, *u8) {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
let new_min_chunk_size = uint::max(&n_bytes, &chunk_size);
self.chunks = @cons(copy self.head, self.chunks);
self.head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
......
......@@ -772,7 +772,7 @@ fn read(buf: &[mut u8], len: uint) -> uint {
}
}
let count = uint::min(len, self.data.buf.len());
let count = uint::min(&len, &self.data.buf.len());
let mut data = ~[];
self.data.buf <-> data;
......
......@@ -30,7 +30,7 @@ fn map_slices<A: copy send, B: copy send>(
~[f()(0u, xs)]
}
else {
let num_tasks = uint::min(max_tasks, len / min_granularity);
let num_tasks = uint::min(&max_tasks, &(len / min_granularity));
let items_per_task = len / num_tasks;
......@@ -38,7 +38,7 @@ fn map_slices<A: copy send, B: copy send>(
let mut base = 0u;
log(info, ~"spawning tasks");
while base < len {
let end = uint::min(len, base + items_per_task);
let end = uint::min(&len, &(base + items_per_task));
// FIXME: why is the ::<A, ()> annotation required here? (#2617)
do vec::as_buf::<A, ()>(xs) |p, _len| {
let f = f();
......
......@@ -1002,7 +1002,7 @@ fn concat2(left: @node, right: @node) -> @node {
right : right,
char_len: char_len(left) + char_len(right),
byte_len: byte_len(left) + byte_len(right),
height: uint::max(height(left), height(right)) + 1u
height: uint::max(&height(left), &height(right)) + 1u
})
}
......
......@@ -563,8 +563,8 @@ fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
let min = @mut int::max_value;
let max = @mut int::min_value;
do visit_ids_fn |id| {
*min = int::min(*min, id);
*max = int::max(*max, id + 1);
*min = int::min(min, &id);
*max = int::max(max, &(id + 1));
}
return {min:*min, max:*max};
}
......
......@@ -182,7 +182,7 @@ fn trim_whitespace_prefix_and_push_line(&lines: ~[~str],
s: ~str, col: uint) unsafe {
let mut s1;
let len = str::len(s);
if all_whitespace(s, 0u, uint::min(len, col)) {
if all_whitespace(s, 0u, uint::min(&len, &col)) {
if col < len {
s1 = str::slice(s, col, len);
} else { s1 = ~""; }
......
......@@ -128,7 +128,7 @@ fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
assert len1 > 0u;
assert len2 > 0u;
let max_common_path = uint::min(len1, len2) - 1u;
let max_common_path = uint::min(&len1, &len2) - 1u;
let mut start_idx = 0u;
while start_idx < max_common_path
&& split1[start_idx] == split2[start_idx] {
......
......@@ -81,7 +81,7 @@ fn usage(argv0: ~str) {
fn describe_warnings() {
let lint_dict = lint::get_lint_dict();
let mut max_key = 0u;
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
for lint_dict.each_key |k| { max_key = uint::max(&k.len(), &max_key); }
fn padded(max: uint, s: ~str) -> ~str {
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
}
......
......@@ -82,7 +82,7 @@ fn ty_align(ty: TypeRef) -> uint {
3 /* double */ => 8u,
10 /* struct */ => {
do vec::foldl(0u, struct_tys(ty)) |a, t| {
uint::max(a, ty_align(t))
uint::max(&a, &ty_align(t))
}
}
11 /* array */ => {
......
......@@ -1856,9 +1856,9 @@ fn type_size(cx: ctxt, ty: t) -> uint {
let variants = substd_enum_variants(cx, did, substs);
variants.foldl( // find max size of any variant
0,
|m, v| uint::max(m,
|m, v| uint::max(&m,
// find size of this variant:
v.args.foldl(0, |s, a| s + type_size(cx, a))))
&v.args.foldl(0, |s, a| s + type_size(cx, a))))
}
ty_param(_) | ty_self => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册