std: Mark some functions as pure

This commit is contained in:
Chris Peterson
2012-12-23 14:38:01 -08:00
parent 6d8621ae7f
commit ffaa477368
4 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -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)
}
+1 -1
View File
@@ -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;
}
+6 -6
View File
@@ -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 fn has<T: Copy Eq>(ls: @List<T>, elt: 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 @@ pub fn len<T>(ls: @List<T>) -> uint {
*/
/// 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 {
+4 -4
View File
@@ -43,7 +43,7 @@
*/
/// Create an empty rope
pub fn empty() -> Rope {
pub pure fn empty() -> Rope {
return node::Empty;
}
@@ -479,7 +479,7 @@ pub fn next(it: &node::char_iterator::T) -> Option<char> {
*
* 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 @@ pub fn concat2(left: @Node, right: @Node) -> @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 @@ pub fn loop_leaves(node: @Node, it: fn(Leaf) -> bool) -> bool{
* 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 {