mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-06 20:13:42 +00:00
std: Mark some functions as pure
This commit is contained in:
parent
6d8621ae7f
commit
ffaa477368
@ -95,7 +95,7 @@ pub fn Arena() -> Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn round_up_to(base: uint, align: uint) -> uint {
|
||||
pure fn round_up_to(base: uint, align: uint) -> uint {
|
||||
(base + (align - 1)) & !(align - 1)
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ pub fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
|
||||
*/
|
||||
|
||||
/// Returns the length of the vector
|
||||
pub fn len<T>(t: CVec<T>) -> uint {
|
||||
pub pure fn len<T>(t: CVec<T>) -> uint {
|
||||
return (*t).len;
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ pub enum List<T> {
|
||||
Nil,
|
||||
}
|
||||
|
||||
/// Cregate a list from a vector
|
||||
pub fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
|
||||
/// Create a list from a vector
|
||||
pub pure fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
|
||||
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ pub fn foldl<T: Copy, U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
|
||||
* When function `f` returns true then an option containing the element
|
||||
* is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pub fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
|
||||
pub pure fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
|
||||
let mut ls = ls;
|
||||
loop {
|
||||
ls = match *ls {
|
||||
@ -88,7 +88,7 @@ pub pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
|
||||
}
|
||||
|
||||
/// Returns the length of a list
|
||||
pub fn len<T>(ls: @List<T>) -> uint {
|
||||
pub pure fn len<T>(ls: @List<T>) -> uint {
|
||||
let mut count = 0u;
|
||||
iter(ls, |_e| count += 1u);
|
||||
count
|
||||
@ -131,7 +131,7 @@ pure fn push<T: Copy>(ll: &mut @list<T>, vv: T) {
|
||||
*/
|
||||
|
||||
/// Iterate over a list
|
||||
pub fn iter<T>(l: @List<T>, f: fn(&T)) {
|
||||
pub pure fn iter<T>(l: @List<T>, f: fn(&T)) {
|
||||
let mut cur = l;
|
||||
loop {
|
||||
cur = match *cur {
|
||||
@ -145,7 +145,7 @@ pub fn iter<T>(l: @List<T>, f: fn(&T)) {
|
||||
}
|
||||
|
||||
/// Iterate over a list
|
||||
pub fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
|
||||
pub pure fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
|
||||
let mut cur = l;
|
||||
loop {
|
||||
cur = match *cur {
|
||||
|
@ -43,7 +43,7 @@ pub type Rope = node::Root;
|
||||
*/
|
||||
|
||||
/// Create an empty rope
|
||||
pub fn empty() -> Rope {
|
||||
pub pure fn empty() -> Rope {
|
||||
return node::Empty;
|
||||
}
|
||||
|
||||
@ -479,7 +479,7 @@ pub mod iterator {
|
||||
*
|
||||
* Constant time.
|
||||
*/
|
||||
pub fn height(rope: Rope) -> uint {
|
||||
pub pure fn height(rope: Rope) -> uint {
|
||||
match (rope) {
|
||||
node::Empty => return 0u,
|
||||
node::Content(x) => return node::height(x)
|
||||
@ -1019,7 +1019,7 @@ mod node {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn height(node: @Node) -> uint {
|
||||
pub pure fn height(node: @Node) -> uint {
|
||||
match (*node) {
|
||||
Leaf(_) => return 0u,
|
||||
Concat(ref x) => return x.height
|
||||
@ -1100,7 +1100,7 @@ mod node {
|
||||
* proportional to the height of the rope + the (bounded)
|
||||
* length of the largest leaf.
|
||||
*/
|
||||
pub fn char_at(node: @Node, pos: uint) -> char {
|
||||
pub pure fn char_at(node: @Node, pos: uint) -> char {
|
||||
let mut node = node;
|
||||
let mut pos = pos;
|
||||
loop {
|
||||
|
Loading…
Reference in New Issue
Block a user