core: marked fns as pure where possible
This commit is contained in:
parent
1fe4bd0f43
commit
bfbaadc694
@ -123,7 +123,7 @@ Returns:
|
||||
|
||||
An u8 whose first bit is set if `if_true(v)` holds
|
||||
*/
|
||||
fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } }
|
||||
pure fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } }
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust;
|
||||
|
@ -10,7 +10,7 @@ Function: ptr_eq
|
||||
|
||||
Determine if two shared boxes point to the same object
|
||||
*/
|
||||
fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||
// FIXME: ptr::addr_of
|
||||
unsafe {
|
||||
let a_ptr: uint = unsafe::reinterpret_cast(a);
|
||||
|
@ -122,7 +122,7 @@ pure fn to_digit(c: char) -> u8 unsafe {
|
||||
Convert a char to the corresponding digit. Returns none when the
|
||||
character is not a valid hexadecimal digit.
|
||||
*/
|
||||
fn maybe_digit(c: char) -> option::t<u8> {
|
||||
pure fn maybe_digit(c: char) -> option::t<u8> {
|
||||
alt c {
|
||||
'0' to '9' { option::some(c as u8 - ('0' as u8)) }
|
||||
'a' to 'z' { option::some(c as u8 + 10u8 - ('a' as u8)) }
|
||||
@ -143,7 +143,7 @@ fn maybe_digit(c: char) -> option::t<u8> {
|
||||
Returns:
|
||||
-1 if a<b, 0 if a==b, +1 if a>b
|
||||
*/
|
||||
fn cmp(a: char, b: char) -> int {
|
||||
pure fn cmp(a: char, b: char) -> int {
|
||||
ret if b > a { -1 }
|
||||
else if b < a { 1 }
|
||||
else { 0 }
|
||||
|
@ -30,7 +30,7 @@ Failure:
|
||||
|
||||
Fails if the value equals `none`.
|
||||
*/
|
||||
fn get<copy T>(opt: t<T>) -> T {
|
||||
pure fn get<copy T>(opt: t<T>) -> T {
|
||||
alt opt { some(x) { ret x; } none. { fail "option none"; } }
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ Function: from_maybe
|
||||
|
||||
Returns the contained value or a default
|
||||
*/
|
||||
fn from_maybe<T>(def: T, opt: t<T>) -> T {
|
||||
pure fn from_maybe<T>(def: T, opt: t<T>) -> T {
|
||||
alt opt { some(x) { x } none. { def } }
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,14 @@ Function: eq
|
||||
|
||||
Bytewise string equality
|
||||
*/
|
||||
fn eq(&&a: str, &&b: str) -> bool { a == b }
|
||||
pure fn eq(&&a: str, &&b: str) -> bool { a == b }
|
||||
|
||||
/*
|
||||
Function: lteq
|
||||
|
||||
Bytewise less than or equal
|
||||
*/
|
||||
fn lteq(&&a: str, &&b: str) -> bool { a <= b }
|
||||
pure fn lteq(&&a: str, &&b: str) -> bool { a <= b }
|
||||
|
||||
/*
|
||||
Function: hash
|
||||
@ -131,7 +131,7 @@ Function: byte_len
|
||||
|
||||
Returns the length in bytes of a string
|
||||
*/
|
||||
fn byte_len(s: str) -> uint unsafe {
|
||||
pure fn byte_len(s: str) -> uint unsafe {
|
||||
let v: [u8] = unsafe::reinterpret_cast(s);
|
||||
let vlen = vec::len(v);
|
||||
unsafe::leak(v);
|
||||
@ -261,7 +261,7 @@ Function: utf8_char_width
|
||||
|
||||
FIXME: What does this function do?
|
||||
*/
|
||||
fn utf8_char_width(b: u8) -> uint {
|
||||
pure fn utf8_char_width(b: u8) -> uint {
|
||||
let byte: uint = b as uint;
|
||||
if byte < 128u { ret 1u; }
|
||||
if byte < 192u {
|
||||
|
@ -42,7 +42,7 @@ Function: last_os_error
|
||||
Get a string representing the platform-dependent last error
|
||||
*/
|
||||
fn last_os_error() -> str {
|
||||
ret rustrt::last_os_error();
|
||||
rustrt::last_os_error()
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -181,7 +181,7 @@ Returns the first element of a vector
|
||||
Predicates:
|
||||
<is_not_empty> (v)
|
||||
*/
|
||||
fn head<copy T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
|
||||
pure fn head<copy T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
|
||||
|
||||
/*
|
||||
Function: tail
|
||||
@ -221,7 +221,7 @@ Returns:
|
||||
An option containing the last element of `v` if `v` is not empty, or
|
||||
none if `v` is empty.
|
||||
*/
|
||||
fn last<copy T>(v: [const T]) -> option::t<T> {
|
||||
pure fn last<copy T>(v: [const T]) -> option::t<T> {
|
||||
if len(v) == 0u { ret none; }
|
||||
ret some(v[len(v) - 1u]);
|
||||
}
|
||||
@ -234,7 +234,7 @@ Returns the last element of a non-empty vector `v`
|
||||
Predicates:
|
||||
<is_not_empty> (v)
|
||||
*/
|
||||
fn last_total<copy T>(v: [const T]) : is_not_empty(v) -> T {
|
||||
pure fn last_total<copy T>(v: [const T]) : is_not_empty(v) -> T {
|
||||
ret v[len(v) - 1u];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user