From ffaa47736866ca89b8d23cd3f14d54efefdb6243 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 23 Dec 2012 14:38:01 -0800 Subject: std: Mark some functions as pure --- src/libstd/arena.rs | 2 +- src/libstd/c_vec.rs | 2 +- src/libstd/list.rs | 12 ++++++------ src/libstd/rope.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 105e8fb122f..9054f9355ad 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -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) } diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index cd1fa33a08f..cc8cadb709d 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -135,7 +135,7 @@ pub fn set(t: CVec, ofs: uint, v: T) { */ /// Returns the length of the vector -pub fn len(t: CVec) -> uint { +pub pure fn len(t: CVec) -> uint { return (*t).len; } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 6d2c10eb827..e41aab8ec1f 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -22,8 +22,8 @@ pub enum List { Nil, } -/// Cregate a list from a vector -pub fn from_vec(v: &[T]) -> @List { +/// Create a list from a vector +pub pure fn from_vec(v: &[T]) -> @List { vec::foldr(v, @Nil::, |h, t| @Cons(*h, t)) } @@ -53,7 +53,7 @@ pub fn foldl(z: T, ls: @List, 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(ls: @List, f: fn(&T) -> bool) -> Option { +pub pure fn find(ls: @List, f: fn(&T) -> bool) -> Option { let mut ls = ls; loop { ls = match *ls { @@ -88,7 +88,7 @@ pub pure fn is_not_empty(ls: @List) -> bool { } /// Returns the length of a list -pub fn len(ls: @List) -> uint { +pub pure fn len(ls: @List) -> uint { let mut count = 0u; iter(ls, |_e| count += 1u); count @@ -131,7 +131,7 @@ pure fn push(ll: &mut @list, vv: T) { */ /// Iterate over a list -pub fn iter(l: @List, f: fn(&T)) { +pub pure fn iter(l: @List, f: fn(&T)) { let mut cur = l; loop { cur = match *cur { @@ -145,7 +145,7 @@ pub fn iter(l: @List, f: fn(&T)) { } /// Iterate over a list -pub fn each(l: @List, f: fn(&T) -> bool) { +pub pure fn each(l: @List, f: fn(&T) -> bool) { let mut cur = l; loop { cur = match *cur { diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 473992e6820..aa78d22e4c8 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -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 { -- cgit 1.4.1-3-g733a5