core: Demode int/uint mods
This commit is contained in:
parent
ee2ce036cc
commit
c0c8d3aa8f
15 changed files with 34 additions and 26 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
// NB: transitionary, de-mode-ing.
|
||||||
|
#[forbid(deprecated_mode)];
|
||||||
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
import T = inst::T;
|
import T = inst::T;
|
||||||
import cmp::{Eq, Ord};
|
import cmp::{Eq, Ord};
|
||||||
import num::from_int;
|
import num::from_int;
|
||||||
|
@ -21,8 +25,8 @@ const bytes : uint = (inst::bits / 8);
|
||||||
const min_value: T = (-1 as T) << (bits - 1);
|
const min_value: T = (-1 as T) << (bits - 1);
|
||||||
const max_value: T = min_value - 1 as T;
|
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 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 max(x: &T, y: &T) -> T { if *x > *y { *x } else { *y } }
|
||||||
|
|
||||||
pure fn add(x: &T, y: &T) -> T { *x + *y }
|
pure fn add(x: &T, y: &T) -> T { *x + *y }
|
||||||
pure fn sub(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
|
/// 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
|
/// Convert to a string in a given base
|
||||||
fn to_str(n: T, radix: uint) -> ~str {
|
fn to_str(n: T, radix: uint) -> ~str {
|
||||||
|
@ -235,7 +239,7 @@ fn test_to_str() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_interfaces() {
|
fn test_interfaces() {
|
||||||
fn test<U:num::Num>(ten: U) {
|
fn test<U:num::Num>(+ten: U) {
|
||||||
assert (ten.to_int() == 10);
|
assert (ten.to_int() == 10);
|
||||||
|
|
||||||
let two: U = from_int(2);
|
let two: U = from_int(2);
|
||||||
|
|
|
@ -284,7 +284,7 @@ type ByteBuf = {buf: &[const u8], mut pos: uint};
|
||||||
|
|
||||||
impl ByteBuf: Reader {
|
impl ByteBuf: Reader {
|
||||||
fn read(buf: &[mut u8], len: uint) -> uint {
|
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::u8::memcpy(buf,
|
||||||
vec::const_view(self.buf, self.pos, self.buf.len()),
|
vec::const_view(self.buf, self.pos, self.buf.len()),
|
||||||
|
|
|
@ -676,7 +676,7 @@ pure fn eq_slice(a: &str, b: &str) -> bool {
|
||||||
let a_len = a.len();
|
let a_len = a.len();
|
||||||
let b_len = b.len();
|
let b_len = b.len();
|
||||||
if a_len != b_len { return false; }
|
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;
|
let mut i = 0u;
|
||||||
while i < end {
|
while i < end {
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// NB: transitionary, de-mode-ing.
|
||||||
|
#[forbid(deprecated_mode)];
|
||||||
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
import T = inst::T;
|
import T = inst::T;
|
||||||
import cmp::{Eq, Ord};
|
import cmp::{Eq, Ord};
|
||||||
|
|
||||||
|
@ -20,8 +24,8 @@ const bytes : uint = (inst::bits / 8);
|
||||||
const min_value: T = 0 as T;
|
const min_value: T = 0 as T;
|
||||||
const max_value: T = 0 as T - 1 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 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 max(x: &T, y: &T) -> T { if *x > *y { *x } else { *y } }
|
||||||
|
|
||||||
pure fn add(x: &T, y: &T) -> T { *x + *y }
|
pure fn add(x: &T, y: &T) -> T { *x + *y }
|
||||||
pure fn sub(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
|
/// 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.
|
/// 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; }
|
if str::len(buf) == 0u { return None; }
|
||||||
let mut i = str::len(buf) - 1u;
|
let mut i = str::len(buf) - 1u;
|
||||||
let mut power = 1u64, n = 0u64;
|
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 {
|
pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
|
||||||
let (a_len, b_len) = (a.len(), b.len());
|
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;
|
let mut i = 0;
|
||||||
while i < end {
|
while i < end {
|
||||||
|
@ -1821,7 +1821,7 @@ mod u8 {
|
||||||
pure fn cmp(a: &~[u8], b: &~[u8]) -> int {
|
pure fn cmp(a: &~[u8], b: &~[u8]) -> int {
|
||||||
let a_len = len(*a);
|
let a_len = len(*a);
|
||||||
let b_len = len(*b);
|
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 {
|
let r = unsafe {
|
||||||
libc::memcmp(unsafe::to_ptr(*a) as *libc::c_void,
|
libc::memcmp(unsafe::to_ptr(*a) as *libc::c_void,
|
||||||
unsafe::to_ptr(*b) as *libc::c_void, n) as int
|
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 {
|
fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 {
|
||||||
// Allocate a new chunk.
|
// Allocate a new chunk.
|
||||||
let chunk_size = at_vec::capacity(self.pod_head.data);
|
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.chunks = @cons(copy self.pod_head, self.chunks);
|
||||||
self.pod_head =
|
self.pod_head =
|
||||||
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
|
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
|
||||||
|
@ -177,7 +177,7 @@ impl &Arena {
|
||||||
fn alloc_nonpod_grow(n_bytes: uint, align: uint) -> (*u8, *u8) {
|
fn alloc_nonpod_grow(n_bytes: uint, align: uint) -> (*u8, *u8) {
|
||||||
// Allocate a new chunk.
|
// Allocate a new chunk.
|
||||||
let chunk_size = at_vec::capacity(self.head.data);
|
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.chunks = @cons(copy self.head, self.chunks);
|
||||||
self.head =
|
self.head =
|
||||||
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
|
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
|
||||||
|
|
|
@ -772,7 +772,7 @@ impl tcp_socket_buf: io::Reader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let count = uint::min(len, self.data.buf.len());
|
let count = uint::min(&len, &self.data.buf.len());
|
||||||
|
|
||||||
let mut data = ~[];
|
let mut data = ~[];
|
||||||
self.data.buf <-> data;
|
self.data.buf <-> data;
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn map_slices<A: copy send, B: copy send>(
|
||||||
~[f()(0u, xs)]
|
~[f()(0u, xs)]
|
||||||
}
|
}
|
||||||
else {
|
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;
|
let items_per_task = len / num_tasks;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ fn map_slices<A: copy send, B: copy send>(
|
||||||
let mut base = 0u;
|
let mut base = 0u;
|
||||||
log(info, ~"spawning tasks");
|
log(info, ~"spawning tasks");
|
||||||
while base < len {
|
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)
|
// FIXME: why is the ::<A, ()> annotation required here? (#2617)
|
||||||
do vec::as_buf::<A, ()>(xs) |p, _len| {
|
do vec::as_buf::<A, ()>(xs) |p, _len| {
|
||||||
let f = f();
|
let f = f();
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ mod node {
|
||||||
right : right,
|
right : right,
|
||||||
char_len: char_len(left) + char_len(right),
|
char_len: char_len(left) + char_len(right),
|
||||||
byte_len: byte_len(left) + byte_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 min = @mut int::max_value;
|
||||||
let max = @mut int::min_value;
|
let max = @mut int::min_value;
|
||||||
do visit_ids_fn |id| {
|
do visit_ids_fn |id| {
|
||||||
*min = int::min(*min, id);
|
*min = int::min(min, &id);
|
||||||
*max = int::max(*max, id + 1);
|
*max = int::max(max, &(id + 1));
|
||||||
}
|
}
|
||||||
return {min:*min, max:*max};
|
return {min:*min, max:*max};
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ fn trim_whitespace_prefix_and_push_line(&lines: ~[~str],
|
||||||
s: ~str, col: uint) unsafe {
|
s: ~str, col: uint) unsafe {
|
||||||
let mut s1;
|
let mut s1;
|
||||||
let len = str::len(s);
|
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 {
|
if col < len {
|
||||||
s1 = str::slice(s, col, len);
|
s1 = str::slice(s, col, len);
|
||||||
} else { s1 = ~""; }
|
} else { s1 = ~""; }
|
||||||
|
|
|
@ -128,7 +128,7 @@ fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
|
||||||
assert len1 > 0u;
|
assert len1 > 0u;
|
||||||
assert len2 > 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;
|
let mut start_idx = 0u;
|
||||||
while start_idx < max_common_path
|
while start_idx < max_common_path
|
||||||
&& split1[start_idx] == split2[start_idx] {
|
&& split1[start_idx] == split2[start_idx] {
|
||||||
|
|
|
@ -81,7 +81,7 @@ Options:
|
||||||
fn describe_warnings() {
|
fn describe_warnings() {
|
||||||
let lint_dict = lint::get_lint_dict();
|
let lint_dict = lint::get_lint_dict();
|
||||||
let mut max_key = 0u;
|
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 {
|
fn padded(max: uint, s: ~str) -> ~str {
|
||||||
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
|
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
|
||||||
3 /* double */ => 8u,
|
3 /* double */ => 8u,
|
||||||
10 /* struct */ => {
|
10 /* struct */ => {
|
||||||
do vec::foldl(0u, struct_tys(ty)) |a, t| {
|
do vec::foldl(0u, struct_tys(ty)) |a, t| {
|
||||||
uint::max(a, ty_align(t))
|
uint::max(&a, &ty_align(t))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11 /* array */ => {
|
11 /* array */ => {
|
||||||
|
|
|
@ -1856,9 +1856,9 @@ fn type_size(cx: ctxt, ty: t) -> uint {
|
||||||
let variants = substd_enum_variants(cx, did, substs);
|
let variants = substd_enum_variants(cx, did, substs);
|
||||||
variants.foldl( // find max size of any variant
|
variants.foldl( // find max size of any variant
|
||||||
0,
|
0,
|
||||||
|m, v| uint::max(m,
|
|m, v| uint::max(&m,
|
||||||
// find size of this variant:
|
// 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 => {
|
ty_param(_) | ty_self => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue