Skip to content

Depure libcore and libstd #5488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod rustrt {

/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pub pure fn capacity<T>(v: @[const T]) -> uint {
pub fn capacity<T>(v: @[const T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::reinterpret_cast(&addr_of(&v));
Expand All @@ -59,8 +59,7 @@ pub pure fn capacity<T>(v: @[const T]) -> uint {
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build_sized<A>(size: uint,
builder: &fn(push: &pure fn(v: A))) -> @[A] {
pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] {
let mut vec: @[const A] = @[];
unsafe { raw::reserve(&mut vec, size); }
builder(|+x| unsafe { raw::push(&mut vec, x) });
Expand All @@ -78,7 +77,7 @@ pub pure fn build_sized<A>(size: uint,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
pub fn build<A>(builder: &fn(push: &fn(v: A))) -> @[A] {
build_sized(4, builder)
}

Expand All @@ -95,14 +94,15 @@ pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: &pure fn(v: A))) -> @[A] {
pub fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: &fn(v: A)))
-> @[A] {
build_sized(size.get_or_default(4), builder)
}

// Appending
#[inline(always)]
pub pure fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
pub fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
do build_sized(lhs.len() + rhs.len()) |push| {
for vec::each(lhs) |x| { push(*x); }
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
Expand All @@ -111,7 +111,7 @@ pub pure fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {


/// Apply a function to each element of a vector and return the results
pub pure fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
do build_sized(v.len()) |push| {
for vec::each(v) |elem| {
push(f(elem));
Expand All @@ -125,7 +125,7 @@ pub pure fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }
Expand All @@ -138,7 +138,7 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
pub pure fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(copy t); i += 1u; }
Expand Down Expand Up @@ -176,7 +176,7 @@ pub mod traits {

impl<T:Copy> Add<&'self [const T],@[T]> for @[T] {
#[inline(always)]
pure fn add(&self, rhs: & &'self [const T]) -> @[T] {
fn add(&self, rhs: & &'self [const T]) -> @[T] {
append(*self, (*rhs))
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@ use from_str::FromStr;
#[cfg(notest)] use cmp;

/// Negation / inverse
pub pure fn not(v: bool) -> bool { !v }
pub fn not(v: bool) -> bool { !v }

/// Conjunction
pub pure fn and(a: bool, b: bool) -> bool { a && b }
pub fn and(a: bool, b: bool) -> bool { a && b }

/// Disjunction
pub pure fn or(a: bool, b: bool) -> bool { a || b }
pub fn or(a: bool, b: bool) -> bool { a || b }

/**
* Exclusive or
*
* Identical to `or(and(a, not(b)), and(not(a), b))`
*/
pub pure fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }

/// Implication in the logic, i.e. from `a` follows `b`
pub pure fn implies(a: bool, b: bool) -> bool { !a || b }
pub fn implies(a: bool, b: bool) -> bool { !a || b }

/// true if truth values `a` and `b` are indistinguishable in the logic
pub pure fn eq(a: bool, b: bool) -> bool { a == b }
pub fn eq(a: bool, b: bool) -> bool { a == b }

/// true if truth values `a` and `b` are distinguishable in the logic
pub pure fn ne(a: bool, b: bool) -> bool { a != b }
pub fn ne(a: bool, b: bool) -> bool { a != b }

/// true if `v` represents truth in the logic
pub pure fn is_true(v: bool) -> bool { v }
pub fn is_true(v: bool) -> bool { v }

/// true if `v` represents falsehood in the logic
pub pure fn is_false(v: bool) -> bool { !v }
pub fn is_false(v: bool) -> bool { !v }

/// Parse logic value from `s`
impl FromStr for bool {
static pure fn from_str(s: &str) -> Option<bool> {
fn from_str(s: &str) -> Option<bool> {
if s == "true" {
Some(true)
} else if s == "false" {
Expand All @@ -61,7 +61,7 @@ impl FromStr for bool {
}

/// Convert `v` into a string
pub pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }

/**
* Iterates over all truth values by passing them to `blk` in an unspecified
Expand All @@ -73,12 +73,12 @@ pub fn all_values(blk: &fn(v: bool)) {
}

/// converts truth value to an 8 bit byte
pub pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }

#[cfg(notest)]
impl cmp::Eq for bool {
pure fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
pure fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ pub struct Cell<T> {
}

impl<T:cmp::Eq> cmp::Eq for Cell<T> {
pure fn eq(&self, other: &Cell<T>) -> bool {
fn eq(&self, other: &Cell<T>) -> bool {
unsafe {
let frozen_self: &Option<T> = transmute(&mut self.value);
let frozen_other: &Option<T> = transmute(&mut other.value);
frozen_self == frozen_other
}
}
pure fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
}

/// Creates a new full cell with the given value.
pub fn Cell<T>(value: T) -> Cell<T> {
Cell { value: Some(value) }
}

pub pure fn empty_cell<T>() -> Cell<T> {
pub fn empty_cell<T>() -> Cell<T> {
Cell { value: None }
}

Expand All @@ -61,7 +61,7 @@ pub impl<T> Cell<T> {
}

/// Returns true if the cell is empty and false if the cell is full.
pure fn is_empty(&self) -> bool {
fn is_empty(&self) -> bool {
self.value.is_none()
}

Expand Down
28 changes: 14 additions & 14 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub use is_XID_continue = unicode::derived_property::XID_Continue;
* in terms of the Unicode General Category 'Ll'
*/
#[inline(always)]
pub pure fn is_lowercase(c: char) -> bool {
pub fn is_lowercase(c: char) -> bool {
return unicode::general_category::Ll(c);
}

Expand All @@ -70,7 +70,7 @@ pub pure fn is_lowercase(c: char) -> bool {
* in terms of the Unicode General Category 'Lu'.
*/
#[inline(always)]
pub pure fn is_uppercase(c: char) -> bool {
pub fn is_uppercase(c: char) -> bool {
return unicode::general_category::Lu(c);
}

Expand All @@ -80,7 +80,7 @@ pub pure fn is_uppercase(c: char) -> bool {
* additional 'Cc'-category control codes in the range [0x09, 0x0d]
*/
#[inline(always)]
pub pure fn is_whitespace(c: char) -> bool {
pub fn is_whitespace(c: char) -> bool {
return ('\x09' <= c && c <= '\x0d')
|| unicode::general_category::Zs(c)
|| unicode::general_category::Zl(c)
Expand All @@ -93,7 +93,7 @@ pub pure fn is_whitespace(c: char) -> bool {
* and the Derived Core Property 'Alphabetic'.
*/
#[inline(always)]
pub pure fn is_alphanumeric(c: char) -> bool {
pub fn is_alphanumeric(c: char) -> bool {
return unicode::derived_property::Alphabetic(c) ||
unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
Expand All @@ -102,13 +102,13 @@ pub pure fn is_alphanumeric(c: char) -> bool {

/// Indicates whether the character is an ASCII character
#[inline(always)]
pub pure fn is_ascii(c: char) -> bool {
pub fn is_ascii(c: char) -> bool {
c - ('\x7F' & c) == '\x00'
}

/// Indicates whether the character is numeric (Nd, Nl, or No)
#[inline(always)]
pub pure fn is_digit(c: char) -> bool {
pub fn is_digit(c: char) -> bool {
return unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
unicode::general_category::No(c);
Expand All @@ -127,7 +127,7 @@ pub pure fn is_digit(c: char) -> bool {
* Note: This just wraps `to_digit()`.
*/
#[inline(always)]
pub pure fn is_digit_radix(c: char, radix: uint) -> bool {
pub fn is_digit_radix(c: char, radix: uint) -> bool {
match to_digit(c, radix) {
Some(_) => true,
None => false
Expand All @@ -148,7 +148,7 @@ pub pure fn is_digit_radix(c: char, radix: uint) -> bool {
* Fails if given a `radix` outside the range `[0..36]`.
*/
#[inline]
pub pure fn to_digit(c: char, radix: uint) -> Option<uint> {
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
if radix > 36 {
fail!(fmt!("to_digit: radix %? is to high (maximum 36)", radix));
}
Expand All @@ -171,7 +171,7 @@ pub pure fn to_digit(c: char, radix: uint) -> Option<uint> {
* Fails if given an `radix` > 36.
*/
#[inline]
pub pure fn from_digit(num: uint, radix: uint) -> Option<char> {
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
if radix > 36 {
fail!(fmt!("from_digit: radix %? is to high (maximum 36)", num));
}
Expand All @@ -195,7 +195,7 @@ pub pure fn from_digit(num: uint, radix: uint) -> Option<char> {
* - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
* - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
*/
pub pure fn escape_unicode(c: char) -> ~str {
pub fn escape_unicode(c: char) -> ~str {
let s = u32::to_str_radix(c as u32, 16u);
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
else if c <= '\uffff' { ('u', 4u) }
Expand Down Expand Up @@ -223,7 +223,7 @@ pub pure fn escape_unicode(c: char) -> ~str {
* - Any other chars in the range [0x20,0x7e] are not escaped.
* - Any other chars are given hex unicode escapes; see `escape_unicode`.
*/
pub pure fn escape_default(c: char) -> ~str {
pub fn escape_default(c: char) -> ~str {
match c {
'\t' => ~"\\t",
'\r' => ~"\\r",
Expand All @@ -244,16 +244,16 @@ pub pure fn escape_default(c: char) -> ~str {
* -1 if a < b, 0 if a == b, +1 if a > b
*/
#[inline(always)]
pub pure fn cmp(a: char, b: char) -> int {
pub fn cmp(a: char, b: char) -> int {
return if b > a { -1 }
else if b < a { 1 }
else { 0 }
}

#[cfg(notest)]
impl Eq for char {
pure fn eq(&self, other: &char) -> bool { (*self) == (*other) }
pure fn ne(&self, other: &char) -> bool { (*self) != (*other) }
fn eq(&self, other: &char) -> bool { (*self) == (*other) }
fn ne(&self, other: &char) -> bool { (*self) != (*other) }
}

#[test]
Expand Down
Loading