RIMOV core::vec
Also remove as many uses as possible of vec::cast_to_mut and cast_from_mut
This commit is contained in:
parent
4de76aeb14
commit
e6c82c0375
@ -322,8 +322,8 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
|
||||
ProcRes: ProcRes) {
|
||||
|
||||
// true if we found the error in question
|
||||
let found_flags = vec::cast_to_mut(vec::from_elem(
|
||||
vec::len(expected_errors), false));
|
||||
let mut found_flags = vec::from_elem(
|
||||
vec::len(expected_errors), false);
|
||||
|
||||
if ProcRes.status == 0 {
|
||||
fatal(~"process did not return an error status");
|
||||
|
@ -79,7 +79,7 @@ pub fn as_c_charp<T>(s: &str, f: fn(*c_char) -> T) -> T {
|
||||
|
||||
pub fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
|
||||
-> Option<~str> {
|
||||
let buf = vec::cast_to_mut(vec::from_elem(TMPBUF_SZ, 0u8 as c_char));
|
||||
let mut buf = vec::from_elem(TMPBUF_SZ, 0u8 as c_char);
|
||||
do vec::as_mut_buf(buf) |b, sz| {
|
||||
if f(b, sz as size_t) {
|
||||
unsafe {
|
||||
@ -108,7 +108,7 @@ pub mod win32 {
|
||||
let mut res = None;
|
||||
let mut done = false;
|
||||
while !done {
|
||||
let buf = vec::cast_to_mut(vec::from_elem(n as uint, 0u16));
|
||||
let mut buf = vec::from_elem(n as uint, 0u16);
|
||||
do vec::as_mut_buf(buf) |b, _sz| {
|
||||
let k : DWORD = f(b, TMPBUF_SZ as DWORD);
|
||||
if k == (0 as DWORD) {
|
||||
@ -1325,7 +1325,7 @@ mod tests {
|
||||
};
|
||||
assert (ostream as uint != 0u);
|
||||
let s = ~"hello";
|
||||
let mut buf = vec::cast_to_mut(str::to_bytes(s) + ~[0 as u8]);
|
||||
let mut buf = str::to_bytes(s) + ~[0 as u8];
|
||||
do vec::as_mut_buf(buf) |b, _len| {
|
||||
assert (libc::fwrite(b as *c_void, 1u as size_t,
|
||||
(str::len(s) + 1u) as size_t, ostream)
|
||||
|
@ -558,10 +558,6 @@ pub fn consume<T>(mut v: ~[T], f: fn(uint, v: T)) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn consume_mut<T>(v: ~[mut T], f: fn(uint, v: T)) {
|
||||
consume(vec::cast_from_mut(v), f)
|
||||
}
|
||||
|
||||
/// Remove the last element from a vector and return it
|
||||
pub fn pop<T>(v: &mut ~[T]) -> T {
|
||||
let ln = v.len();
|
||||
@ -728,11 +724,6 @@ pub pure fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
|
||||
v
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn append_mut<T: Copy>(lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] {
|
||||
cast_to_mut(append(cast_from_mut(lhs), rhs))
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands a vector in place, initializing the new elements to a given value
|
||||
*
|
||||
@ -1285,12 +1276,12 @@ pub pure fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] {
|
||||
* * a - The index of the first element
|
||||
* * b - The index of the second element
|
||||
*/
|
||||
pub fn swap<T>(v: &[mut T], a: uint, b: uint) {
|
||||
pub fn swap<T>(v: &mut [T], a: uint, b: uint) {
|
||||
v[a] <-> v[b];
|
||||
}
|
||||
|
||||
/// Reverse the order of elements in a vector, in place
|
||||
pub fn reverse<T>(v: &[mut T]) {
|
||||
pub fn reverse<T>(v: &mut [T]) {
|
||||
let mut i: uint = 0;
|
||||
let ln = len::<T>(v);
|
||||
while i < ln / 2 { v[i] <-> v[ln - i - 1]; i += 1; }
|
||||
@ -1371,7 +1362,7 @@ pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) {
|
||||
/// a vector with mutable contents and you would like
|
||||
/// to mutate the contents as you iterate.
|
||||
#[inline(always)]
|
||||
pub fn each_mut<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
|
||||
pub fn each_mut<T>(v: &mut [T], f: fn(elem: &mut T) -> bool) {
|
||||
let mut i = 0;
|
||||
let n = v.len();
|
||||
while i < n {
|
||||
@ -1541,7 +1532,7 @@ pub pure fn as_const_buf<T,U>(s: &[const T],
|
||||
|
||||
/// Similar to `as_imm_buf` but passing a `*mut T`
|
||||
#[inline(always)]
|
||||
pub pure fn as_mut_buf<T,U>(s: &[mut T],
|
||||
pub pure fn as_mut_buf<T,U>(s: &mut [T],
|
||||
f: fn(*mut T, uint) -> U) -> U {
|
||||
|
||||
unsafe {
|
||||
@ -1653,7 +1644,7 @@ impl<T: Ord> @[T] : Ord {
|
||||
pub mod traits {
|
||||
use kinds::Copy;
|
||||
use ops::Add;
|
||||
use vec::{append, append_mut};
|
||||
use vec::append;
|
||||
|
||||
impl<T: Copy> ~[T] : Add<&[const T],~[T]> {
|
||||
#[inline(always)]
|
||||
@ -1661,13 +1652,6 @@ pub mod traits {
|
||||
append(copy *self, (*rhs))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy> ~[mut T] : Add<&[const T],~[mut T]> {
|
||||
#[inline(always)]
|
||||
pure fn add(&self, rhs: & &self/[const T]) -> ~[mut T] {
|
||||
append_mut(copy *self, (*rhs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> &[const T]: Container {
|
||||
@ -2088,7 +2072,7 @@ pub mod raw {
|
||||
|
||||
/** see `to_ptr()` */
|
||||
#[inline(always)]
|
||||
pub unsafe fn to_mut_ptr<T>(v: &[mut T]) -> *mut T {
|
||||
pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
|
||||
let repr: **SliceRepr = ::cast::transmute(&v);
|
||||
return ::cast::reinterpret_cast(&addr_of(&((**repr).data)));
|
||||
}
|
||||
@ -2121,7 +2105,7 @@ pub mod raw {
|
||||
* is newly allocated.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub unsafe fn init_elem<T>(v: &[mut T], i: uint, val: T) {
|
||||
pub unsafe fn init_elem<T>(v: &mut [T], i: uint, val: T) {
|
||||
let mut box = Some(val);
|
||||
do as_mut_buf(v) |p, _len| {
|
||||
let mut box2 = None;
|
||||
@ -2155,7 +2139,7 @@ pub mod raw {
|
||||
* may overlap.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub unsafe fn copy_memory<T>(dst: &[mut T], src: &[const T],
|
||||
pub unsafe fn copy_memory<T>(dst: &mut [T], src: &[const T],
|
||||
count: uint) {
|
||||
assert dst.len() >= count;
|
||||
assert src.len() >= count;
|
||||
@ -2222,7 +2206,7 @@ pub mod bytes {
|
||||
* may overlap.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn copy_memory(dst: &[mut u8], src: &[const u8], count: uint) {
|
||||
pub fn copy_memory(dst: &mut [u8], src: &[const u8], count: uint) {
|
||||
// Bound checks are done at vec::raw::copy_memory.
|
||||
unsafe { vec::raw::copy_memory(dst, src, count) }
|
||||
}
|
||||
@ -3220,7 +3204,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn reverse_and_reversed() {
|
||||
let v: ~[mut int] = ~[mut 10, 20];
|
||||
let mut v: ~[int] = ~[10, 20];
|
||||
assert (v[0] == 10);
|
||||
assert (v[1] == 20);
|
||||
reverse(v);
|
||||
@ -3235,13 +3219,13 @@ mod tests {
|
||||
|
||||
let v4 = reversed::<int>(~[]);
|
||||
assert (v4 == ~[]);
|
||||
let v3: ~[mut int] = ~[mut];
|
||||
let mut v3: ~[int] = ~[];
|
||||
reverse::<int>(v3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reversed_mut() {
|
||||
let v2 = reversed::<int>(~[mut 10, 20]);
|
||||
let mut v2 = reversed::<int>(~[10, 20]);
|
||||
assert (v2[0] == 20);
|
||||
assert (v2[1] == 10);
|
||||
}
|
||||
@ -3625,20 +3609,6 @@ mod tests {
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(windows)]
|
||||
#[should_fail]
|
||||
fn test_consume_mut_fail() {
|
||||
let v = ~[mut (~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||
let mut i = 0;
|
||||
do consume_mut(v) |_i, _elt| {
|
||||
if i == 2 {
|
||||
die!()
|
||||
}
|
||||
i += 1;
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(windows)]
|
||||
#[should_fail]
|
||||
@ -3657,7 +3627,7 @@ mod tests {
|
||||
#[ignore(windows)]
|
||||
#[should_fail]
|
||||
fn test_map_fail() {
|
||||
let v = [mut (~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||
let mut v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||
let mut i = 0;
|
||||
do map(v) |_elt| {
|
||||
if i == 2 {
|
||||
@ -3983,7 +3953,7 @@ mod tests {
|
||||
#[ignore(cfg(windows))]
|
||||
#[should_fail]
|
||||
fn test_as_mut_buf_fail() {
|
||||
let v = [mut (~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||
let mut v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||
do as_mut_buf(v) |_buf, _i| {
|
||||
die!()
|
||||
}
|
||||
@ -3994,7 +3964,7 @@ mod tests {
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_copy_memory_oob() {
|
||||
unsafe {
|
||||
let a = [mut 1, 2, 3, 4];
|
||||
let mut a = [1, 2, 3, 4];
|
||||
let b = [1, 2, 3, 4, 5];
|
||||
raw::copy_memory(a, b, 5);
|
||||
}
|
||||
|
@ -1002,7 +1002,7 @@ pub fn pick_col(m: &[@Match]) -> uint {
|
||||
_ => 0u
|
||||
}
|
||||
}
|
||||
let scores = vec::cast_to_mut(vec::from_elem(m[0].pats.len(), 0u));
|
||||
let mut scores = vec::from_elem(m[0].pats.len(), 0u);
|
||||
for vec::each(m) |br| {
|
||||
let mut i = 0u;
|
||||
for vec::each(br.pats) |p| { scores[i] += score(*p); i += 1u; }
|
||||
|
@ -270,14 +270,15 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
|
||||
}
|
||||
|
||||
let words = (ty_size(ty) + 7) / 8;
|
||||
let cls = vec::cast_to_mut(vec::from_elem(words, no_class));
|
||||
let mut cls = vec::from_elem(words, no_class);
|
||||
if words > 4 {
|
||||
all_mem(cls);
|
||||
return vec::cast_from_mut(move cls);
|
||||
let cls = cls;
|
||||
return move cls;
|
||||
}
|
||||
classify(ty, cls, 0, 0);
|
||||
fixup(ty, cls);
|
||||
return vec::cast_from_mut(move cls);
|
||||
return move cls;
|
||||
}
|
||||
|
||||
fn llreg_ty(cls: &[x86_64_reg_class]) -> TypeRef {
|
||||
|
@ -3131,7 +3131,7 @@ pub fn check_bounds_are_used(ccx: @mut CrateCtxt,
|
||||
|
||||
// make a vector of booleans initially false, set to true when used
|
||||
if tps.len() == 0u { return; }
|
||||
let tps_used = vec::cast_to_mut(vec::from_elem(tps.len(), false));
|
||||
let mut tps_used = vec::from_elem(tps.len(), false);
|
||||
|
||||
ty::walk_regions_and_ty(
|
||||
ccx.tcx, ty,
|
||||
|
@ -224,7 +224,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
|
||||
unsafe {
|
||||
let n_opts = opts.len();
|
||||
fn f(_x: uint) -> ~[Optval] { return ~[]; }
|
||||
let vals = vec::cast_to_mut(vec::from_fn(n_opts, f));
|
||||
let mut vals = vec::from_fn(n_opts, f);
|
||||
let mut free: ~[~str] = ~[];
|
||||
let l = args.len();
|
||||
let mut i = 0;
|
||||
@ -339,7 +339,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
|
||||
i += 1;
|
||||
}
|
||||
return Ok(Matches {opts: vec::from_slice(opts),
|
||||
vals: vec::cast_from_mut(move vals),
|
||||
vals: move vals,
|
||||
free: free});
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ pub pure fn md4(msg: &[u8]) -> Quad {
|
||||
|
||||
let mut i = 0u;
|
||||
let e = vec::len(msg);
|
||||
let x = vec::cast_to_mut(vec::from_elem(16u, 0u32));
|
||||
let mut x = vec::from_elem(16u, 0u32);
|
||||
while i < e {
|
||||
let aa = a, bb = b, cc = c, dd = d;
|
||||
|
||||
|
@ -174,7 +174,7 @@ pub fn concat(v: ~[Rope]) -> Rope {
|
||||
//Copy `v` into a mut vector
|
||||
let mut len = vec::len(v);
|
||||
if len == 0u { return node::Empty; }
|
||||
let ropes = vec::cast_to_mut(vec::from_elem(len, v[0]));
|
||||
let mut ropes = vec::from_elem(len, v[0]);
|
||||
for uint::range(1u, len) |i| {
|
||||
ropes[i] = v[i];
|
||||
}
|
||||
@ -719,7 +719,7 @@ pub mod node {
|
||||
//Firstly, split `str` in slices of hint_max_leaf_char_len
|
||||
let mut leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
|
||||
//Number of leaves
|
||||
let nodes = vec::cast_to_mut(vec::from_elem(leaves, candidate));
|
||||
let mut nodes = vec::from_elem(leaves, candidate);
|
||||
|
||||
let mut i = 0u;
|
||||
let mut offset = byte_start;
|
||||
@ -832,7 +832,7 @@ pub mod node {
|
||||
|
||||
pub fn serialize_node(node: @Node) -> ~str {
|
||||
unsafe {
|
||||
let mut buf = vec::cast_to_mut(vec::from_elem(byte_len(node), 0));
|
||||
let mut buf = vec::from_elem(byte_len(node), 0);
|
||||
let mut offset = 0u;//Current position in the buffer
|
||||
let it = leaf_iterator::start(node);
|
||||
loop {
|
||||
|
@ -35,21 +35,21 @@ use core::vec;
|
||||
/// The SHA-1 interface
|
||||
trait Sha1 {
|
||||
/// Provide message input as bytes
|
||||
fn input(&[const u8]);
|
||||
fn input(&mut self, &[const u8]);
|
||||
/// Provide message input as string
|
||||
fn input_str(&str);
|
||||
fn input_str(&mut self, &str);
|
||||
/**
|
||||
* Read the digest as a vector of 20 bytes. After calling this no further
|
||||
* input may be provided until reset is called.
|
||||
*/
|
||||
fn result() -> ~[u8];
|
||||
fn result(&mut self) -> ~[u8];
|
||||
/**
|
||||
* Read the digest as a hex string. After calling this no further
|
||||
* input may be provided until reset is called.
|
||||
*/
|
||||
fn result_str() -> ~str;
|
||||
fn result_str(&mut self) -> ~str;
|
||||
/// Reset the SHA-1 state for reuse
|
||||
fn reset();
|
||||
fn reset(&mut self);
|
||||
}
|
||||
|
||||
// Some unexported constants
|
||||
@ -65,15 +65,15 @@ const k3: u32 = 0xCA62C1D6u32;
|
||||
/// Construct a `sha` object
|
||||
pub fn sha1() -> Sha1 {
|
||||
struct Sha1State
|
||||
{h: ~[mut u32],
|
||||
mut len_low: u32,
|
||||
mut len_high: u32,
|
||||
msg_block: ~[mut u8],
|
||||
mut msg_block_idx: uint,
|
||||
mut computed: bool,
|
||||
work_buf: @~[mut u32]};
|
||||
{ h: ~[u32],
|
||||
len_low: u32,
|
||||
len_high: u32,
|
||||
msg_block: ~[u8],
|
||||
msg_block_idx: uint,
|
||||
computed: bool,
|
||||
work_buf: @mut ~[u32]};
|
||||
|
||||
fn add_input(st: &Sha1State, msg: &[const u8]) {
|
||||
fn add_input(st: &mut Sha1State, msg: &[const u8]) {
|
||||
assert (!st.computed);
|
||||
for vec::each_const(msg) |element| {
|
||||
st.msg_block[st.msg_block_idx] = *element;
|
||||
@ -89,11 +89,11 @@ pub fn sha1() -> Sha1 {
|
||||
if st.msg_block_idx == msg_block_len { process_msg_block(st); }
|
||||
}
|
||||
}
|
||||
fn process_msg_block(st: &Sha1State) {
|
||||
fn process_msg_block(st: &mut Sha1State) {
|
||||
assert (vec::len(st.h) == digest_buf_len);
|
||||
assert (vec::len(*st.work_buf) == work_buf_len);
|
||||
let mut t: int; // Loop counter
|
||||
let w = st.work_buf;
|
||||
let mut w = st.work_buf;
|
||||
|
||||
// Initialize the first 16 words of the vector w
|
||||
t = 0;
|
||||
@ -168,7 +168,7 @@ pub fn sha1() -> Sha1 {
|
||||
fn circular_shift(bits: u32, word: u32) -> u32 {
|
||||
return word << bits | word >> 32u32 - bits;
|
||||
}
|
||||
fn mk_result(st: &Sha1State) -> ~[u8] {
|
||||
fn mk_result(st: &mut Sha1State) -> ~[u8] {
|
||||
if !(*st).computed { pad_msg(st); (*st).computed = true; }
|
||||
let mut rs: ~[u8] = ~[];
|
||||
for vec::each_mut((*st).h) |ptr_hpart| {
|
||||
@ -191,7 +191,7 @@ pub fn sha1() -> Sha1 {
|
||||
* call process_msg_block() appropriately. When it returns, it
|
||||
* can be assumed that the message digest has been computed.
|
||||
*/
|
||||
fn pad_msg(st: &Sha1State) {
|
||||
fn pad_msg(st: &mut Sha1State) {
|
||||
assert (vec::len((*st).msg_block) == msg_block_len);
|
||||
|
||||
/*
|
||||
@ -229,7 +229,7 @@ pub fn sha1() -> Sha1 {
|
||||
}
|
||||
|
||||
impl Sha1State: Sha1 {
|
||||
fn reset() {
|
||||
fn reset(&mut self) {
|
||||
assert (vec::len(self.h) == digest_buf_len);
|
||||
self.len_low = 0u32;
|
||||
self.len_high = 0u32;
|
||||
@ -241,14 +241,14 @@ pub fn sha1() -> Sha1 {
|
||||
self.h[4] = 0xC3D2E1F0u32;
|
||||
self.computed = false;
|
||||
}
|
||||
fn input(msg: &[const u8]) { add_input(&self, msg); }
|
||||
fn input_str(msg: &str) {
|
||||
fn input(&mut self, msg: &[const u8]) { add_input(self, msg); }
|
||||
fn input_str(&mut self, msg: &str) {
|
||||
let bs = str::to_bytes(msg);
|
||||
add_input(&self, bs);
|
||||
add_input(self, bs);
|
||||
}
|
||||
fn result() -> ~[u8] { return mk_result(&self); }
|
||||
fn result_str() -> ~str {
|
||||
let rr = mk_result(&self);
|
||||
fn result(&mut self) -> ~[u8] { return mk_result(self); }
|
||||
fn result_str(&mut self) -> ~str {
|
||||
let rr = mk_result(self);
|
||||
let mut s = ~"";
|
||||
for vec::each(rr) |b| {
|
||||
s += uint::to_str_radix(*b as uint, 16u);
|
||||
@ -256,16 +256,16 @@ pub fn sha1() -> Sha1 {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
let st = Sha1State {
|
||||
h: vec::cast_to_mut(vec::from_elem(digest_buf_len, 0u32)),
|
||||
mut len_low: 0u32,
|
||||
mut len_high: 0u32,
|
||||
msg_block: vec::cast_to_mut(vec::from_elem(msg_block_len, 0u8)),
|
||||
mut msg_block_idx: 0u,
|
||||
mut computed: false,
|
||||
work_buf: @vec::cast_to_mut(vec::from_elem(work_buf_len, 0u32))
|
||||
let mut st = Sha1State {
|
||||
h: vec::from_elem(digest_buf_len, 0u32),
|
||||
len_low: 0u32,
|
||||
len_high: 0u32,
|
||||
msg_block: vec::from_elem(msg_block_len, 0u8),
|
||||
msg_block_idx: 0u,
|
||||
computed: false,
|
||||
work_buf: @mut vec::from_elem(work_buf_len, 0u32)
|
||||
};
|
||||
let sh = (move st) as Sha1;
|
||||
let mut sh = (move st) as Sha1;
|
||||
sh.reset();
|
||||
return sh;
|
||||
}
|
||||
@ -368,7 +368,7 @@ mod tests {
|
||||
}
|
||||
// Test that it works when accepting the message all at once
|
||||
|
||||
let sh = sha1::sha1();
|
||||
let mut sh = sha1::sha1();
|
||||
for vec::each(tests) |t| {
|
||||
sh.input_str(t.input);
|
||||
let out = sh.result();
|
||||
|
@ -455,7 +455,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
base2: uint, len2: uint) {
|
||||
assert len1 != 0 && len2 != 0 && base1+len1 == base2;
|
||||
|
||||
let tmp = vec::cast_to_mut(vec::slice(array, base1, base1+len1));
|
||||
let mut tmp = vec::slice(array, base1, base1+len1);
|
||||
|
||||
let mut c1 = 0;
|
||||
let mut c2 = base2;
|
||||
@ -558,7 +558,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
base2: uint, len2: uint) {
|
||||
assert len1 != 1 && len2 != 0 && base1 + len1 == base2;
|
||||
|
||||
let tmp = vec::cast_to_mut(vec::slice(array, base2, base2+len2));
|
||||
let mut tmp = vec::slice(array, base2, base2+len2);
|
||||
|
||||
let mut c1 = base1 + len1 - 1;
|
||||
let mut c2 = len2 - 1;
|
||||
|
@ -242,13 +242,13 @@ fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
||||
}
|
||||
|
||||
fn digest<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
||||
let sha = sha1::sha1();
|
||||
let mut sha = sha1::sha1();
|
||||
sha.input_str(json_encode(t));
|
||||
sha.result_str()
|
||||
}
|
||||
|
||||
fn digest_file(path: &Path) -> ~str {
|
||||
let sha = sha1::sha1();
|
||||
let mut sha = sha1::sha1();
|
||||
let s = io::read_whole_file_str(path);
|
||||
sha.input_str(*s.get_ref());
|
||||
sha.result_str()
|
||||
|
@ -14,9 +14,9 @@ extern mod std;
|
||||
fn fannkuch(n: int) -> int {
|
||||
fn perm1init(i: uint) -> int { return i as int; }
|
||||
|
||||
let perm = vec::cast_to_mut(vec::from_elem(n as uint, 0));
|
||||
let perm1 = vec::cast_to_mut(vec::from_fn(n as uint, |i| perm1init(i)));
|
||||
let count = vec::cast_to_mut(vec::from_elem(n as uint, 0));
|
||||
let mut perm = vec::from_elem(n as uint, 0);
|
||||
let mut perm1 = vec::from_fn(n as uint, |i| perm1init(i));
|
||||
let mut count = vec::from_elem(n as uint, 0);
|
||||
let mut f = 0;
|
||||
let mut i = 0;
|
||||
let mut k = 0;
|
||||
|
@ -149,7 +149,7 @@ fn main() {
|
||||
// initialize each sequence sorter
|
||||
let sizes = ~[1,2,3,4,6,12,18];
|
||||
let streams = vec::map(sizes, |_sz| Some(stream()));
|
||||
let streams = vec::cast_to_mut(move streams);
|
||||
let mut streams = move streams;
|
||||
let mut from_child = ~[];
|
||||
let to_child = vec::mapi(sizes, |ii, sz| {
|
||||
let sz = *sz;
|
||||
|
@ -45,7 +45,7 @@ fn eval_At_times_u(u: &[const float], Au: &mut [float]) {
|
||||
}
|
||||
|
||||
fn eval_AtA_times_u(u: &[const float], AtAu: &mut [float]) {
|
||||
let v = vec::cast_to_mut(vec::from_elem(vec::len(u), 0.0));
|
||||
let mut v = vec::from_elem(vec::len(u), 0.0);
|
||||
eval_A_times_u(u, v);
|
||||
eval_At_times_u(v, AtAu);
|
||||
}
|
||||
@ -62,8 +62,8 @@ fn main() {
|
||||
|
||||
let N = uint::from_str(args[1]).get();
|
||||
|
||||
let u = vec::cast_to_mut(vec::from_elem(N, 1.0));
|
||||
let v = vec::cast_to_mut(vec::from_elem(N, 0.0));
|
||||
let mut u = vec::from_elem(N, 1.0);
|
||||
let mut v = vec::from_elem(N, 0.0);
|
||||
let mut i = 0u;
|
||||
while i < 10u {
|
||||
eval_AtA_times_u(u, v);
|
||||
|
@ -33,8 +33,8 @@ fn main() {
|
||||
{
|
||||
let mut res = foo(x);
|
||||
|
||||
let mut v = ~[mut];
|
||||
v = move ~[mut (move res)] + v; //~ ERROR does not fulfill `Copy`
|
||||
let mut v = ~[];
|
||||
v = move ~[(move res)] + v; //~ instantiating a type parameter with an incompatible type `foo`, which does not fulfill `Copy`
|
||||
assert (v.len() == 2);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
// Once cast_to_mut is removed, pick a better function to import
|
||||
// for this test!
|
||||
use vec::cast_to_mut;
|
||||
log(debug, vec::len(cast_to_mut(~[1, 2])));
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user