core: Demode int/uint mods

This commit is contained in:
Brian Anderson
2012-08-29 16:11:06 -07:00
parent ee2ce036cc
commit c0c8d3aa8f
15 changed files with 34 additions and 26 deletions

View File

@@ -1,3 +1,7 @@
// 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 bytes : uint = (inst::bits / 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);

View File

@@ -284,7 +284,7 @@ type ByteBuf = {buf: &[const u8], mut pos: uint};
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()),

View File

@@ -676,7 +676,7 @@ pure fn eq_slice(a: &str, b: &str) -> bool {
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 {

View File

@@ -1,3 +1,7 @@
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
import T = inst::T;
import cmp::{Eq, Ord};
@@ -20,8 +24,8 @@ const bytes : uint = (inst::bits / 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;

View File

@@ -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