remove the redundant each method from OptVec

This commit is contained in:
Daniel Micay 2013-06-24 17:19:28 -04:00
parent 032dcc57e8
commit 5242e8d2ba
11 changed files with 19 additions and 26 deletions

View File

@ -731,8 +731,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
} }
let mut combined_ty_params = opt_vec::Empty; let mut combined_ty_params = opt_vec::Empty;
for owner_generics.ty_params.each |x| { combined_ty_params.push(copy *x) } for owner_generics.ty_params.iter().advance |x| { combined_ty_params.push(copy *x) }
for method_generics.ty_params.each |x| { combined_ty_params.push(copy *x) } for method_generics.ty_params.iter().advance |x| { combined_ty_params.push(copy *x) }
let len = combined_ty_params.len(); let len = combined_ty_params.len();
encode_type_param_bounds(ebml_w, ecx, &combined_ty_params); encode_type_param_bounds(ebml_w, ecx, &combined_ty_params);

View File

@ -3834,8 +3834,8 @@ impl Resolver {
pub fn resolve_type_parameters(@mut self, pub fn resolve_type_parameters(@mut self,
type_parameters: &OptVec<TyParam>, type_parameters: &OptVec<TyParam>,
visitor: ResolveVisitor) { visitor: ResolveVisitor) {
for type_parameters.each |type_parameter| { for type_parameters.iter().advance |type_parameter| {
for type_parameter.bounds.each |bound| { for type_parameter.bounds.iter().advance |bound| {
self.resolve_type_parameter_bound(bound, visitor); self.resolve_type_parameter_bound(bound, visitor);
} }
} }
@ -4181,13 +4181,13 @@ impl Resolver {
} }
} }
for bounds.each |bound| { for bounds.iter().advance |bound| {
self.resolve_type_parameter_bound(bound, visitor); self.resolve_type_parameter_bound(bound, visitor);
} }
} }
ty_closure(c) => { ty_closure(c) => {
for c.bounds.each |bound| { for c.bounds.iter().advance |bound| {
self.resolve_type_parameter_bound(bound, visitor); self.resolve_type_parameter_bound(bound, visitor);
} }
visit_ty(ty, ((), visitor)); visit_ty(ty, ((), visitor));

View File

@ -752,7 +752,7 @@ fn conv_builtin_bounds(tcx: ty::ctxt,
//! legal. //! legal.
let mut builtin_bounds = ty::EmptyBuiltinBounds(); let mut builtin_bounds = ty::EmptyBuiltinBounds();
for ast_bounds.each |ast_bound| { for ast_bounds.iter().advance |ast_bound| {
match *ast_bound { match *ast_bound {
ast::TraitTyParamBound(b) => { ast::TraitTyParamBound(b) => {
match lookup_def_tcx(tcx, b.path.span, b.ref_id) { match lookup_def_tcx(tcx, b.path.span, b.ref_id) {

View File

@ -775,7 +775,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
span: span, span: span,
generics: &ast::Generics, generics: &ast::Generics,
thing: &'static str) { thing: &'static str) {
for generics.ty_params.each |ty_param| { for generics.ty_params.iter().advance |ty_param| {
if ty_param.bounds.len() > 0 { if ty_param.bounds.len() > 0 {
ccx.tcx.sess.span_err( ccx.tcx.sess.span_err(
span, span,
@ -1172,7 +1172,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
builtin_bounds: ty::EmptyBuiltinBounds(), builtin_bounds: ty::EmptyBuiltinBounds(),
trait_bounds: ~[] trait_bounds: ~[]
}; };
for ast_bounds.each |ast_bound| { for ast_bounds.iter().advance |ast_bound| {
match *ast_bound { match *ast_bound {
TraitTyParamBound(b) => { TraitTyParamBound(b) => {
let ty = ty::mk_param(ccx.tcx, param_ty.idx, param_ty.def_id); let ty = ty::mk_param(ccx.tcx, param_ty.idx, param_ty.def_id);

View File

@ -57,7 +57,7 @@ impl RegionParamNames {
} }
fn has_ident(&self, ident: ast::ident) -> bool { fn has_ident(&self, ident: ast::ident) -> bool {
for self.each |region_param_name| { for self.iter().advance |region_param_name| {
if *region_param_name == ident { if *region_param_name == ident {
return true; return true;
} }

View File

@ -394,10 +394,10 @@ impl id_range {
pub fn id_visitor<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> { pub fn id_visitor<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
let visit_generics: @fn(&Generics, T) = |generics, t| { let visit_generics: @fn(&Generics, T) = |generics, t| {
for generics.ty_params.each |p| { for generics.ty_params.iter().advance |p| {
vfn(p.id, copy t); vfn(p.id, copy t);
} }
for generics.lifetimes.each |p| { for generics.lifetimes.iter().advance |p| {
vfn(p.id, copy t); vfn(p.id, copy t);
} }
}; };

View File

@ -324,11 +324,11 @@ impl<'self> TraitDef<'self> {
let mut trait_generics = self.generics.to_generics(cx, span, type_ident, generics); let mut trait_generics = self.generics.to_generics(cx, span, type_ident, generics);
// Copy the lifetimes // Copy the lifetimes
for generics.lifetimes.each |l| { for generics.lifetimes.iter().advance |l| {
trait_generics.lifetimes.push(copy *l) trait_generics.lifetimes.push(copy *l)
}; };
// Create the type parameters. // Create the type parameters.
for generics.ty_params.each |ty_param| { for generics.ty_params.iter().advance |ty_param| {
// I don't think this can be moved out of the loop, since // I don't think this can be moved out of the loop, since
// a TyParamBound requires an ast id // a TyParamBound requires an ast id
let mut bounds = opt_vec::from( let mut bounds = opt_vec::from(

View File

@ -374,7 +374,7 @@ impl gen_init for protocol {
fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty { fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty {
let mut params: OptVec<ast::TyParam> = opt_vec::Empty; let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
for (copy self.states).iter().advance |s| { for (copy self.states).iter().advance |s| {
for s.generics.ty_params.each |tp| { for s.generics.ty_params.iter().advance |tp| {
match params.iter().find_(|tpp| tp.ident == tpp.ident) { match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp), None => params.push(*tp),
_ => () _ => ()
@ -392,7 +392,7 @@ impl gen_init for protocol {
let ext_cx = cx; let ext_cx = cx;
let mut params: OptVec<ast::TyParam> = opt_vec::Empty; let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
let fields = do (copy self.states).iter().transform |s| { let fields = do (copy self.states).iter().transform |s| {
for s.generics.ty_params.each |tp| { for s.generics.ty_params.iter().advance |tp| {
match params.iter().find_(|tpp| tp.ident == tpp.ident) { match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp), None => params.push(*tp),
_ => () _ => ()

View File

@ -38,13 +38,6 @@ pub fn from<T>(t: ~[T]) -> OptVec<T> {
} }
impl<T> OptVec<T> { impl<T> OptVec<T> {
fn each(&self, blk: &fn(v: &T) -> bool) -> bool {
match *self {
Empty => true,
Vec(ref v) => v.iter().advance(blk)
}
}
fn push(&mut self, t: T) { fn push(&mut self, t: T) {
match *self { match *self {
Vec(ref mut v) => { Vec(ref mut v) => {

View File

@ -1743,7 +1743,7 @@ pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) {
if !bounds.is_empty() { if !bounds.is_empty() {
word(s.s, ":"); word(s.s, ":");
let mut first = true; let mut first = true;
for bounds.each |bound| { for bounds.iter().advance |bound| {
nbsp(s); nbsp(s);
if first { if first {
first = false; first = false;

View File

@ -334,7 +334,7 @@ pub fn visit_foreign_item<E: Copy>(ni: @foreign_item, (e, v): (E, vt<E>)) {
pub fn visit_ty_param_bounds<E: Copy>(bounds: &OptVec<TyParamBound>, pub fn visit_ty_param_bounds<E: Copy>(bounds: &OptVec<TyParamBound>,
(e, v): (E, vt<E>)) { (e, v): (E, vt<E>)) {
for bounds.each |bound| { for bounds.iter().advance |bound| {
match *bound { match *bound {
TraitTyParamBound(ty) => visit_trait_ref(ty, (copy e, v)), TraitTyParamBound(ty) => visit_trait_ref(ty, (copy e, v)),
RegionTyParamBound => {} RegionTyParamBound => {}
@ -343,7 +343,7 @@ pub fn visit_ty_param_bounds<E: Copy>(bounds: &OptVec<TyParamBound>,
} }
pub fn visit_generics<E: Copy>(generics: &Generics, (e, v): (E, vt<E>)) { pub fn visit_generics<E: Copy>(generics: &Generics, (e, v): (E, vt<E>)) {
for generics.ty_params.each |tp| { for generics.ty_params.iter().advance |tp| {
visit_ty_param_bounds(tp.bounds, (copy e, v)); visit_ty_param_bounds(tp.bounds, (copy e, v));
} }
} }