Skip to content

Commit f19fb24

Browse files
committed
Remove standalone comparison functions in vec, make the trait impls better.
1 parent 9207802 commit f19fb24

File tree

15 files changed

+169
-191
lines changed

15 files changed

+169
-191
lines changed

src/compiletest/runtest.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,8 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
601601
ProcArgs {
602602
// If we've got another tool to run under (valgrind),
603603
// then split apart its command
604-
let toolargs = split_maybe_args(&config.runtool);
605-
606-
let mut args = toolargs + [make_exe_name(config, testfile).to_str()];
604+
let mut args = split_maybe_args(&config.runtool);
605+
args.push(make_exe_name(config, testfile).to_str());
607606
let prog = args.shift();
608607
return ProcArgs {prog: prog, args: args};
609608
}

src/libextra/crypto/sha1.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ impl Digest for Sha1 {
240240

241241
#[cfg(test)]
242242
mod tests {
243-
use std::vec;
244243

245244
use digest::{Digest, DigestUtil};
246245
use sha1::Sha1;
@@ -337,7 +336,7 @@ mod tests {
337336
for tests.iter().advance |t| {
338337
(*sh).input_str(t.input);
339338
sh.result(out);
340-
assert!(vec::eq(t.output, out));
339+
assert!(t.output.as_slice() == out);
341340

342341
let out_str = (*sh).result_str();
343342
assert_eq!(out_str.len(), 40);
@@ -357,7 +356,7 @@ mod tests {
357356
left = left - take;
358357
}
359358
sh.result(out);
360-
assert!(vec::eq(t.output, out));
359+
assert!(t.output.as_slice() == out);
361360

362361
let out_str = (*sh).result_str();
363362
assert_eq!(out_str.len(), 40);

src/libextra/flatpipes.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use std::io;
5555
use std::comm::GenericChan;
5656
use std::comm::GenericPort;
5757
use std::sys::size_of;
58-
use std::vec;
5958

6059
/**
6160
A FlatPort, consisting of a `BytePort` that receives byte vectors,
@@ -274,7 +273,7 @@ impl<T,U:Unflattener<T>,P:BytePort> GenericPort<T> for FlatPort<T, U, P> {
274273
}
275274
};
276275

277-
if vec::eq(command, CONTINUE) {
276+
if CONTINUE.as_slice() == command {
278277
let msg_len = match self.byte_port.try_recv(size_of::<u64>()) {
279278
Some(bytes) => {
280279
io::u64_from_be_bytes(bytes, 0, size_of::<u64>())
@@ -931,7 +930,7 @@ mod test {
931930
fn test_try_recv_none3<P:BytePort>(loader: PortLoader<P>) {
932931
static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD];
933932
// The control word is followed by garbage
934-
let bytes = CONTINUE.to_owned() + [0];
933+
let bytes = CONTINUE.to_owned() + &[0u8];
935934
let port = loader(bytes);
936935
let res: Option<int> = port.try_recv();
937936
assert!(res.is_none());
@@ -955,7 +954,7 @@ mod test {
955954
1, sys::size_of::<u64>()) |len_bytes| {
956955
len_bytes.to_owned()
957956
};
958-
let bytes = CONTINUE.to_owned() + len_bytes + [0, 0, 0, 0];
957+
let bytes = CONTINUE.to_owned() + len_bytes + &[0u8, 0, 0, 0];
959958

960959
let port = loader(bytes);
961960

src/libextra/num/bigint.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl Add<BigUint, BigUint> for BigUint {
207207
let new_len = uint::max(self.data.len(), other.data.len());
208208

209209
let mut carry = 0;
210-
let sum = do vec::from_fn(new_len) |i| {
210+
let mut sum = do vec::from_fn(new_len) |i| {
211211
let ai = if i < self.data.len() { self.data[i] } else { 0 };
212212
let bi = if i < other.data.len() { other.data[i] } else { 0 };
213213
let (hi, lo) = BigDigit::from_uint(
@@ -216,8 +216,8 @@ impl Add<BigUint, BigUint> for BigUint {
216216
carry = hi;
217217
lo
218218
};
219-
if carry == 0 { return BigUint::new(sum) };
220-
return BigUint::new(sum + [carry]);
219+
if carry != 0 { sum.push(carry); }
220+
return BigUint::new(sum);
221221
}
222222
}
223223

@@ -284,15 +284,15 @@ impl Mul<BigUint, BigUint> for BigUint {
284284
if n == 1 { return copy *a; }
285285

286286
let mut carry = 0;
287-
let prod = do a.data.iter().transform |ai| {
287+
let mut prod = do a.data.iter().transform |ai| {
288288
let (hi, lo) = BigDigit::from_uint(
289289
(*ai as uint) * (n as uint) + (carry as uint)
290290
);
291291
carry = hi;
292292
lo
293293
}.collect::<~[BigDigit]>();
294-
if carry == 0 { return BigUint::new(prod) };
295-
return BigUint::new(prod + [carry]);
294+
if carry != 0 { prod.push(carry); }
295+
return BigUint::new(prod);
296296
}
297297

298298

@@ -621,15 +621,15 @@ impl BigUint {
621621
if n_bits == 0 || self.is_zero() { return copy *self; }
622622

623623
let mut carry = 0;
624-
let shifted = do self.data.iter().transform |elem| {
624+
let mut shifted = do self.data.iter().transform |elem| {
625625
let (hi, lo) = BigDigit::from_uint(
626626
(*elem as uint) << n_bits | (carry as uint)
627627
);
628628
carry = hi;
629629
lo
630630
}.collect::<~[BigDigit]>();
631-
if carry == 0 { return BigUint::new(shifted); }
632-
return BigUint::new(shifted + [carry]);
631+
if carry != 0 { shifted.push(carry); }
632+
return BigUint::new(shifted);
633633
}
634634

635635

src/librustc/middle/trans/adt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
131131
}
132132
ty::ty_struct(def_id, ref substs) => {
133133
let fields = ty::lookup_struct_fields(cx.tcx, def_id);
134-
let ftys = do fields.map |field| {
134+
let mut ftys = do fields.map |field| {
135135
ty::lookup_field_type(cx.tcx, def_id, field.id, substs)
136136
};
137137
let packed = ty::lookup_packed(cx.tcx, def_id);
138138
let dtor = ty::ty_dtor(cx.tcx, def_id).has_drop_flag();
139-
let ftys =
140-
if dtor { ftys + [ty::mk_bool()] } else { ftys };
139+
if dtor { ftys.push(ty::mk_bool()); }
140+
141141
return Univariant(mk_struct(cx, ftys, packed), dtor)
142142
}
143143
ty::ty_enum(def_id, ref substs) => {
@@ -263,7 +263,7 @@ fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool) -> ~[Type] {
263263
let padding = largest_size - most_aligned.size;
264264

265265
struct_llfields(cx, most_aligned, sizing)
266-
+ [Type::array(&Type::i8(), padding)]
266+
+ &[Type::array(&Type::i8(), padding)]
267267
}
268268
}
269269
}
@@ -512,7 +512,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: int,
512512
let discr_ty = C_int(ccx, discr);
513513
let contents = build_const_struct(ccx, case,
514514
~[discr_ty] + vals);
515-
C_struct(contents + [padding(max_sz - case.size)])
515+
C_struct(contents + &[padding(max_sz - case.size)])
516516
}
517517
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, _ } => {
518518
if discr == nndiscr {

src/librustc/middle/trans/foreign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn shim_types(ccx: @mut CrateContext, id: ast::node_id) -> ShimTypes {
113113
_ => ccx.sess.bug("c_arg_and_ret_lltys called on non-function type")
114114
};
115115
let llsig = foreign_signature(ccx, &fn_sig);
116-
let bundle_ty = Type::struct_(llsig.llarg_tys + [llsig.llret_ty.ptr_to()], false);
116+
let bundle_ty = Type::struct_(llsig.llarg_tys + &[llsig.llret_ty.ptr_to()], false);
117117
let ret_def = !ty::type_is_bot(fn_sig.output) &&
118118
!ty::type_is_nil(fn_sig.output);
119119
let fn_ty = abi_info(ccx).compute_info(llsig.llarg_tys, llsig.llret_ty, ret_def);

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl Reflector {
278278
let opaqueptrty = ty::mk_ptr(ccx.tcx, ty::mt { ty: opaquety, mutbl: ast::m_imm });
279279

280280
let make_get_disr = || {
281-
let sub_path = bcx.fcx.path + [path_name(special_idents::anon)];
281+
let sub_path = bcx.fcx.path + &[path_name(special_idents::anon)];
282282
let sym = mangle_internal_name_by_path_and_seq(ccx,
283283
sub_path,
284284
"get_disr");

src/librustc/middle/trans/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl Type {
245245
}
246246

247247
pub fn box(ctx: &CrateContext, ty: &Type) -> Type {
248-
Type::struct_(Type::box_header_fields(ctx) + [*ty], false)
248+
Type::struct_(Type::box_header_fields(ctx) + &[*ty], false)
249249
}
250250

251251
pub fn opaque_box(ctx: &CrateContext) -> Type {

src/librustdoc/desc_to_brief_pass.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn first_sentence_(s: &str) -> ~str {
141141
pub fn paragraphs(s: &str) -> ~[~str] {
142142
let mut whitespace_lines = 0;
143143
let mut accum = ~"";
144-
let paras = do s.any_line_iter().fold(~[]) |paras, line| {
144+
let mut paras = do s.any_line_iter().fold(~[]) |paras, line| {
145145
let mut res = paras;
146146

147147
if line.is_whitespace() {
@@ -166,11 +166,8 @@ pub fn paragraphs(s: &str) -> ~[~str] {
166166
res
167167
};
168168

169-
if !accum.is_empty() {
170-
paras + [accum]
171-
} else {
172-
paras
173-
}
169+
if !accum.is_empty() { paras.push(accum); }
170+
paras
174171
}
175172

176173
#[cfg(test)]

src/librustdoc/markdown_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub fn header_kind(doc: doc::ItemTag) -> ~str {
172172
}
173173

174174
pub fn header_name(doc: doc::ItemTag) -> ~str {
175-
let fullpath = (doc.path() + [doc.name()]).connect("::");
175+
let fullpath = (doc.path() + &[doc.name()]).connect("::");
176176
match &doc {
177177
&doc::ModTag(_) if doc.id() != syntax::ast::crate_node_id => {
178178
fullpath

src/librustdoc/markdown_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn make_filename(
163163
}
164164
}
165165
doc::ItemPage(doc) => {
166-
(doc.path() + [doc.name()]).connect("_")
166+
(doc.path() + &[doc.name()]).connect("_")
167167
}
168168
}
169169
};

src/libstd/at_vec.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,14 @@ pub fn to_managed<T:Copy>(v: &[T]) -> @[T] {
176176
#[cfg(not(test))]
177177
pub mod traits {
178178
use at_vec::append;
179+
use vec::Vector;
179180
use kinds::Copy;
180181
use ops::Add;
181182

182-
impl<'self,T:Copy> Add<&'self [T],@[T]> for @[T] {
183+
impl<'self,T:Copy, V: Vector<T>> Add<V,@[T]> for @[T] {
183184
#[inline]
184-
fn add(&self, rhs: & &'self [T]) -> @[T] {
185-
append(*self, (*rhs))
185+
fn add(&self, rhs: &V) -> @[T] {
186+
append(*self, rhs.as_slice())
186187
}
187188
}
188189
}
@@ -312,7 +313,7 @@ mod test {
312313

313314
#[test]
314315
fn append_test() {
315-
assert_eq!(@[1,2,3] + [4,5,6], @[1,2,3,4,5,6]);
316+
assert_eq!(@[1,2,3] + &[4,5,6], @[1,2,3,4,5,6]);
316317
}
317318

318319
#[test]

src/libstd/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub use tuple::{CloneableTuple10, CloneableTuple11, CloneableTuple12};
7272
pub use tuple::{ImmutableTuple2, ImmutableTuple3, ImmutableTuple4, ImmutableTuple5};
7373
pub use tuple::{ImmutableTuple6, ImmutableTuple7, ImmutableTuple8, ImmutableTuple9};
7474
pub use tuple::{ImmutableTuple10, ImmutableTuple11, ImmutableTuple12};
75-
pub use vec::{VectorVector, CopyableVector, ImmutableVector};
75+
pub use vec::{Vector, VectorVector, CopyableVector, ImmutableVector};
7676
pub use vec::{ImmutableEqVector, ImmutableTotalOrdVector, ImmutableCopyableVector};
7777
pub use vec::{OwnedVector, OwnedCopyableVector,OwnedEqVector, MutableVector};
7878
pub use io::{Reader, ReaderUtil, Writer, WriterUtil};

0 commit comments

Comments
 (0)