Skip to content

Commit

Permalink
Replace more vector additions (issue #2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Jun 28, 2012
1 parent 61b1875 commit 0b84437
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,10 @@ pure fn permute<T: copy>(v: [T]/&, put: fn([T]/~)) {
let mut rest = slice(v, 0u, i);
unchecked {
push_all(rest, view(v, i+1u, ln));
permute(rest) {|permutation|
put(append([elt]/~, permutation))
}
}
permute(rest) {|permutation| put([elt]/~ + permutation)}
i += 1u;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/getopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn getopts(args: [str]/~, opts: [opt]/~) -> result unsafe {
let cur = args[i];
let curlen = str::len(cur);
if !is_arg(cur) {
free += [cur]/~;
vec::push(free, cur);
} else if str::eq(cur, "--") {
let mut j = i + 1u;
while j < l { vec::push(free, args[j]); j += 1u; }
Expand All @@ -223,7 +223,7 @@ fn getopts(args: [str]/~, opts: [opt]/~) -> result unsafe {
names = []/~;
while j < curlen {
let range = str::char_range_at(cur, j);
names += [short(range.ch)]/~;
vec::push(names, short(range.ch));
j = range.next;
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ Used when an option accepts multiple values.
fn opt_strs(m: match, nm: str) -> [str]/~ {
let mut acc: [str]/~ = []/~;
for vec::each(opt_vals(m, nm)) {|v|
alt v { val(s) { acc += [s]/~; } _ { } }
alt v { val(s) { vec::push(acc, s); } _ { } }
}
ret acc;
}
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/md4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ fn md4(msg: [u8]/~) -> {a: u32, b: u32, c: u32, d: u32} {
let orig_len: u64 = (vec::len(msg) * 8u) as u64;

// pad message
let mut msg = msg + [0x80u8]/~;
let mut msg = vec::append(msg, [0x80u8]/~);
let mut bitlen = orig_len + 8u64;
while (bitlen + 64u64) % 512u64 > 0u64 {
msg += [0u8]/~;
vec::push(msg, 0u8);
bitlen += 8u64;
}

// append length
let mut i = 0u64;
while i < 8u64 {
msg += [(orig_len >> (i * 8u64)) as u8]/~;
vec::push(msg, (orig_len >> (i * 8u64)) as u8);
i += 1u64;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn sha1() -> sha1 {
let b = (hpart >> 16u32 & 0xFFu32) as u8;
let c = (hpart >> 8u32 & 0xFFu32) as u8;
let d = (hpart & 0xFFu32) as u8;
rs += [a, b, c, d]/~;
rs = vec::append(rs, [a, b, c, d]/~);
}
ret rs;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn merge_sort<T: copy>(le: le<T>, v: [const T]/~) -> [T]/~ {
a_ix += 1u;
} else { vec::push(rs, b[b_ix]); b_ix += 1u; }
}
rs += vec::slice(a, a_ix, a_len);
rs += vec::slice(b, b_ix, b_len);
rs = vec::append(rs, vec::slice(a, a_ix, a_len));
rs = vec::append(rs, vec::slice(b, b_ix, b_len));
ret rs;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn run_tests_console(opts: test_opts,
st.failed += 1u;
write_failed(st.out, st.use_color);
st.out.write_line("");
st.failures += [copy test]/~;
vec::push(st.failures, copy test);
}
tr_ignored {
st.ignored += 1u;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
unsafe fn ip4_addr(ip: str, port: int)
-> sockaddr_in {
let mut addr_vec = str::bytes(ip);
addr_vec += [0u8]/~; // add null terminator
vec::push(addr_vec, 0u8); // add null terminator
let addr_vec_ptr = vec::unsafe::to_ptr(addr_vec);
let ip_back = str::from_bytes(addr_vec);
log(debug, #fmt("vec val: '%s' length: %u",
Expand Down

0 comments on commit 0b84437

Please sign in to comment.