提交 a7ecde33 编写于 作者: E Erick Tryzelaar

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.
上级 95423d28
......@@ -119,8 +119,8 @@ fn chars_from_bytes<T: Reader>(bytes: &~[u8], chars: &mut ~[char])
}
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 {
......
......@@ -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 {
......
......@@ -559,7 +559,7 @@ fn log_simple<T:Repr>() -> bool {
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
}
......
......@@ -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 {
......
......@@ -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);
}
......
......@@ -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 */ }
......
......@@ -34,9 +34,7 @@ fn indenter() -> _indenter {
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
......
......@@ -282,8 +282,7 @@ fn fn_to_str(cx: ctxt, purity: ast::purity, proto: ty::fn_proto,
_ => { }
}
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 field_to_str(cx: ctxt, f: field) -> ~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) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册