Skip to content

Commit 66dc489

Browse files
committed
Merge pull request #4278 from cpeterso/incoming-pure-functions
Mark some more core and std functions as pure
2 parents 2bb2536 + ffaa477 commit 66dc489

File tree

11 files changed

+26
-28
lines changed

11 files changed

+26
-28
lines changed

src/libcore/dvec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ pub pure fn DVec<A>() -> DVec<A> {
6767
}
6868

6969
/// Creates a new dvec with a single element
70-
pub fn from_elem<A>(e: A) -> DVec<A> {
70+
pub pure fn from_elem<A>(e: A) -> DVec<A> {
7171
DVec {mut data: ~[move e]}
7272
}
7373

7474
/// Creates a new dvec with the contents of a vector
75-
pub fn from_vec<A>(v: ~[A]) -> DVec<A> {
75+
pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> {
7676
DVec {mut data: move v}
7777
}
7878

7979
/// Consumes the vector and returns its contents
80-
pub fn unwrap<A>(d: DVec<A>) -> ~[A] {
80+
pub pure fn unwrap<A>(d: DVec<A>) -> ~[A] {
8181
let DVec {data: v} = move d;
8282
move v
8383
}

src/libcore/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub pure fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
188188
* * num - The float value
189189
* * digits - The number of significant digits
190190
*/
191-
pub fn to_str_exact(num: float, digits: uint) -> ~str {
191+
pub pure fn to_str_exact(num: float, digits: uint) -> ~str {
192192
to_str_common(num, digits, true)
193193
}
194194

@@ -238,7 +238,7 @@ pub pure fn to_str(num: float, digits: uint) -> ~str {
238238
* `none` if the string did not represent a valid number. Otherwise,
239239
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
240240
*/
241-
pub fn from_str(num: &str) -> Option<float> {
241+
pub pure fn from_str(num: &str) -> Option<float> {
242242
if num == "inf" {
243243
return Some(infinity as float);
244244
} else if num == "-inf" {

src/libcore/int-template/int.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ mod inst {
1717
pub const bits: uint = uint::bits;
1818

1919
/// Returns `base` raised to the power of `exponent`
20-
pub fn pow(base: int, exponent: uint) -> int {
20+
pub pure fn pow(base: int, exponent: uint) -> int {
2121
if exponent == 0u {
2222
//Not mathemtically true if ~[base == 0]
2323
return 1;
2424
}
25-
if base == 0 { return 0; }
25+
if base == 0 { return 0; }
2626
let mut my_pow = exponent;
2727
let mut acc = 1;
2828
let mut multiplier = base;

src/libcore/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ pub pure fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
170170
(I couldn't think of a cutesy name for this one.)
171171
*/
172172
#[inline(always)]
173-
pub fn to_uint<T>(thing: &T) -> uint unsafe {
173+
pub pure fn to_uint<T>(thing: &T) -> uint unsafe {
174174
cast::reinterpret_cast(&thing)
175175
}
176176

177177
/// Determine if two borrowed pointers point to the same thing.
178178
#[inline(always)]
179-
pub fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
179+
pub pure fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
180180
to_uint(thing) == to_uint(other)
181181
}
182182

src/libcore/rand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ impl XorShiftState: Rng {
309309
}
310310
}
311311

312-
pub fn xorshift() -> Rng {
312+
pub pure fn xorshift() -> Rng {
313313
// constants taken from http://en.wikipedia.org/wiki/Xorshift
314314
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
315315
}
316316

317-
pub fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
317+
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
318318
{mut x: x, mut y: y, mut z: z, mut w: w} as Rng
319319
}
320320

src/libcore/str.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub pure fn connect(v: &[~str], sep: &str) -> ~str {
214214
}
215215

216216
/// Given a string, make a new string with repeated copies of it
217-
pub fn repeat(ss: &str, nn: uint) -> ~str {
217+
pub pure fn repeat(ss: &str, nn: uint) -> ~str {
218218
let mut acc = ~"";
219219
for nn.times { acc += ss; }
220220
acc
@@ -1684,9 +1684,7 @@ pub struct CharRange {
16841684
*
16851685
* This function can be used to iterate over a unicode string in reverse.
16861686
*/
1687-
pure fn char_range_at_reverse(ss: &str, start: uint)
1688-
-> CharRange {
1689-
1687+
pure fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
16901688
let mut prev = start;
16911689

16921690
// while there is a previous byte == 10......

src/libcore/uint-template/uint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mod inst {
104104

105105
/// Returns the smallest power of 2 greater than or equal to `n`
106106
#[inline(always)]
107-
pub fn next_power_of_two(n: uint) -> uint {
107+
pub pure fn next_power_of_two(n: uint) -> uint {
108108
let halfbits: uint = sys::size_of::<uint>() * 4u;
109109
let mut tmp: uint = n - 1u;
110110
let mut shift: uint = 1u;

src/libstd/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn Arena() -> Arena {
9595
}
9696

9797
#[inline(always)]
98-
fn round_up_to(base: uint, align: uint) -> uint {
98+
pure fn round_up_to(base: uint, align: uint) -> uint {
9999
(base + (align - 1)) & !(align - 1)
100100
}
101101

src/libstd/c_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
135135
*/
136136

137137
/// Returns the length of the vector
138-
pub fn len<T>(t: CVec<T>) -> uint {
138+
pub pure fn len<T>(t: CVec<T>) -> uint {
139139
return (*t).len;
140140
}
141141

src/libstd/list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub enum List<T> {
2222
Nil,
2323
}
2424

25-
/// Cregate a list from a vector
26-
pub fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
25+
/// Create a list from a vector
26+
pub pure fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
2727
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
2828
}
2929

@@ -53,7 +53,7 @@ pub fn foldl<T: Copy, U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
5353
* When function `f` returns true then an option containing the element
5454
* is returned. If `f` matches no elements then none is returned.
5555
*/
56-
pub fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
56+
pub pure fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
5757
let mut ls = ls;
5858
loop {
5959
ls = match *ls {
@@ -88,7 +88,7 @@ pub pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
8888
}
8989

9090
/// Returns the length of a list
91-
pub fn len<T>(ls: @List<T>) -> uint {
91+
pub pure fn len<T>(ls: @List<T>) -> uint {
9292
let mut count = 0u;
9393
iter(ls, |_e| count += 1u);
9494
count
@@ -131,7 +131,7 @@ pure fn push<T: Copy>(ll: &mut @list<T>, vv: T) {
131131
*/
132132

133133
/// Iterate over a list
134-
pub fn iter<T>(l: @List<T>, f: fn(&T)) {
134+
pub pure fn iter<T>(l: @List<T>, f: fn(&T)) {
135135
let mut cur = l;
136136
loop {
137137
cur = match *cur {
@@ -145,7 +145,7 @@ pub fn iter<T>(l: @List<T>, f: fn(&T)) {
145145
}
146146

147147
/// Iterate over a list
148-
pub fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
148+
pub pure fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
149149
let mut cur = l;
150150
loop {
151151
cur = match *cur {

src/libstd/rope.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub type Rope = node::Root;
4343
*/
4444

4545
/// Create an empty rope
46-
pub fn empty() -> Rope {
46+
pub pure fn empty() -> Rope {
4747
return node::Empty;
4848
}
4949

@@ -479,7 +479,7 @@ pub mod iterator {
479479
*
480480
* Constant time.
481481
*/
482-
pub fn height(rope: Rope) -> uint {
482+
pub pure fn height(rope: Rope) -> uint {
483483
match (rope) {
484484
node::Empty => return 0u,
485485
node::Content(x) => return node::height(x)
@@ -1019,7 +1019,7 @@ mod node {
10191019
})
10201020
}
10211021

1022-
pub fn height(node: @Node) -> uint {
1022+
pub pure fn height(node: @Node) -> uint {
10231023
match (*node) {
10241024
Leaf(_) => return 0u,
10251025
Concat(ref x) => return x.height
@@ -1100,7 +1100,7 @@ mod node {
11001100
* proportional to the height of the rope + the (bounded)
11011101
* length of the largest leaf.
11021102
*/
1103-
pub fn char_at(node: @Node, pos: uint) -> char {
1103+
pub pure fn char_at(node: @Node, pos: uint) -> char {
11041104
let mut node = node;
11051105
let mut pos = pos;
11061106
loop {

0 commit comments

Comments
 (0)