Skip to content

Mark some more core and std functions as pure #4278

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 2 commits into from
Dec 24, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
std: Mark some functions as pure
  • Loading branch information
cpeterso committed Dec 23, 2012
commit ffaa47736866ca89b8d23cd3f14d54efefdb6243
2 changes: 1 addition & 1 deletion src/libstd/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/c_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/libstd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down