Skip to content

Commit c1e58aa

Browse files
cpetersocatamorphism
authored andcommitted
core: Mark some functions as pure
1 parent 889df54 commit c1e58aa

File tree

7 files changed

+14
-16
lines changed

7 files changed

+14
-16
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;

0 commit comments

Comments
 (0)