libcore: minor code cleanup.

This is minor and probably completely inconsequential to performance,
but I find vec::map to be more clear than vec::each and a push.
This commit is contained in:
Erick Tryzelaar 2012-10-18 09:14:11 -07:00
parent 95423d28f2
commit a7ecde3323
8 changed files with 16 additions and 25 deletions

View File

@ -119,8 +119,8 @@ impl<T: Reader> T : ReaderUtil {
}
return (i, 0);
}
let mut bytes: ~[u8] = ~[];
let mut chars: ~[char] = ~[];
let mut bytes = ~[];
let mut chars = ~[];
// might need more bytes, but reading n will never over-read
let mut nbread = n;
while nbread > 0 {

View File

@ -32,7 +32,7 @@ pub fn console_off() {
#[cfg(notest)]
#[lang="log_type"]
pub fn log_type<T>(level: u32, object: &T) {
let bytes = do io::with_bytes_writer() |writer| {
let bytes = do io::with_bytes_writer |writer| {
repr::write_repr(writer, object);
};
unsafe {

View File

@ -559,7 +559,7 @@ impl ReprPrinter {
unsafe {
self.align(sys::min_align_of::<T>());
let value_addr: &T = transmute(copy self.ptr);
(*value_addr).write_repr(self.writer);
value_addr.write_repr(self.writer);
self.bump(sys::size_of::<T>());
true
}

View File

@ -90,9 +90,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }
// Get the meta_items from inside a vector of attributes
fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
let mut mitems = ~[];
for attrs.each |a| { mitems.push(attr_meta(*a)); }
return mitems;
do attrs.map |a| { attr_meta(*a) }
}
fn desugar_doc_attr(attr: &ast::attribute) -> ast::attribute {

View File

@ -27,8 +27,7 @@ fn declare_upcalls(targ_cfg: @session::config,
fn decl(llmod: ModuleRef, prefix: ~str, name: ~str,
tys: ~[TypeRef], rv: TypeRef) ->
ValueRef {
let mut arg_tys: ~[TypeRef] = ~[];
for tys.each |t| { arg_tys.push(*t); }
let arg_tys = tys.map(|t| *t);
let fn_ty = T_fn(arg_tys, rv);
return base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
}

View File

@ -598,13 +598,12 @@ fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
let ctor_ty = item_type({crate: cdata.cnum, node: id}, item,
tcx, cdata);
let name = item_name(intr, item);
let mut arg_tys: ~[ty::t] = ~[];
match ty::get(ctor_ty).sty {
ty::ty_fn(f) => {
for f.sig.inputs.each |a| { arg_tys.push(a.ty); }
}
_ => { /* Nullary enum variant. */ }
}
let arg_tys = match ty::get(ctor_ty).sty {
ty::ty_fn(f) => f.sig.inputs.map(|a| a.ty),
// Nullary enum variant.
_ => ~[],
};
match variant_disr_val(item) {
Some(val) => { disr_val = val; }
_ => { /* empty */ }

View File

@ -34,9 +34,7 @@ type flag = HashMap<~str, ()>;
fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; }
fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
let mut es = ~[];
for fields.each |f| { es.push(f.node.expr); }
return es;
fields.map(|f| f.node.expr)
}
// Takes a predicate p, returns true iff p is true for any subexpressions

View File

@ -282,8 +282,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str {
_ => { }
}
s += ~"(";
let mut strs = ~[];
for inputs.each |a| { strs.push(fn_input_to_str(cx, *a)); }
let strs = inputs.map(|a| fn_input_to_str(cx, *a));
s += str::connect(strs, ~", ");
s += ~")";
if ty::get(output).sty != ty_nil {
@ -338,13 +337,11 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" }
ty_type => ~"type",
ty_rec(elems) => {
let mut strs: ~[~str] = ~[];
for elems.each |fld| { strs.push(field_to_str(cx, *fld)); }
let strs = elems.map(|fld| field_to_str(cx, *fld));
~"{" + str::connect(strs, ~",") + ~"}"
}
ty_tup(elems) => {
let mut strs = ~[];
for elems.each |elem| { strs.push(ty_to_str(cx, *elem)); }
let strs = elems.map(|elem| ty_to_str(cx, *elem));
~"(" + str::connect(strs, ~",") + ~")"
}
ty_fn(ref f) => {