Skip to content

Commit 8f2a731

Browse files
committed
syntax: replace OptVec with plain Vec.
The new vector representation has no allocations when empty, so OptVec is now useless overhead.
1 parent 6e7f170 commit 8f2a731

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+226
-482
lines changed

src/librustc/front/std_inject.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use syntax::codemap::DUMMY_SP;
1919
use syntax::codemap;
2020
use syntax::fold::Folder;
2121
use syntax::fold;
22-
use syntax::opt_vec;
2322
use syntax::parse::token::InternedString;
2423
use syntax::parse::token;
2524
use syntax::util::small_vector::SmallVector;
@@ -164,13 +163,13 @@ impl fold::Folder for PreludeInjector {
164163
segments: vec!(
165164
ast::PathSegment {
166165
identifier: token::str_to_ident("std"),
167-
lifetimes: opt_vec::Empty,
168-
types: opt_vec::Empty,
166+
lifetimes: Vec::new(),
167+
types: Vec::new(),
169168
},
170169
ast::PathSegment {
171170
identifier: token::str_to_ident("prelude"),
172-
lifetimes: opt_vec::Empty,
173-
types: opt_vec::Empty,
171+
lifetimes: Vec::new(),
172+
types: Vec::new(),
174173
}),
175174
};
176175

src/librustc/front/test.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use syntax::codemap;
3030
use syntax::ext::base::ExtCtxt;
3131
use syntax::fold::Folder;
3232
use syntax::fold;
33-
use syntax::opt_vec;
3433
use syntax::parse::token::InternedString;
3534
use syntax::parse::token;
3635
use syntax::print::pprust;
@@ -370,8 +369,8 @@ fn path_node(ids: ~[ast::Ident]) -> ast::Path {
370369
global: false,
371370
segments: ids.move_iter().map(|identifier| ast::PathSegment {
372371
identifier: identifier,
373-
lifetimes: opt_vec::Empty,
374-
types: opt_vec::Empty,
372+
lifetimes: Vec::new(),
373+
types: Vec::new(),
375374
}).collect()
376375
}
377376
}
@@ -382,8 +381,8 @@ fn path_node_global(ids: ~[ast::Ident]) -> ast::Path {
382381
global: true,
383382
segments: ids.move_iter().map(|identifier| ast::PathSegment {
384383
identifier: identifier,
385-
lifetimes: opt_vec::Empty,
386-
types: opt_vec::Empty,
384+
lifetimes: Vec::new(),
385+
types: Vec::new(),
387386
}).collect()
388387
}
389388
}

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use middle::ty;
2020

2121
use std::str;
2222
use std::uint;
23+
use std::vec_ng::Vec;
2324
use syntax::abi::AbiSet;
2425
use syntax::abi;
2526
use syntax::ast;
2627
use syntax::ast::*;
27-
use syntax::opt_vec;
2828
use syntax::parse::token;
2929

3030
// Compact string representation for ty::t values. API ty_str &
@@ -192,7 +192,7 @@ fn parse_region_substs(st: &mut PState, conv: conv_did) -> ty::RegionSubsts {
192192
match next(st) {
193193
'e' => ty::ErasedRegions,
194194
'n' => {
195-
let mut regions = opt_vec::Empty;
195+
let mut regions = Vec::new();
196196
while peek(st) != '.' {
197197
let r = parse_region(st, |x,y| conv(x,y));
198198
regions.push(r);

src/librustc/middle/borrowck/move_data.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ comments in the section "Moves and initialization" and in `doc.rs`.
1717

1818
use std::cell::RefCell;
1919
use std::uint;
20+
use std::vec_ng::Vec;
2021
use collections::{HashMap, HashSet};
2122
use middle::borrowck::*;
2223
use middle::dataflow::DataFlowContext;
@@ -26,8 +27,6 @@ use middle::typeck;
2627
use syntax::ast;
2728
use syntax::ast_util;
2829
use syntax::codemap::Span;
29-
use syntax::opt_vec::OptVec;
30-
use syntax::opt_vec;
3130
use util::ppaux::Repr;
3231

3332
pub struct MoveData {
@@ -314,15 +313,15 @@ impl MoveData {
314313

315314
fn existing_base_paths(&self,
316315
lp: @LoanPath)
317-
-> OptVec<MovePathIndex> {
318-
let mut result = opt_vec::Empty;
316+
-> Vec<MovePathIndex> {
317+
let mut result = Vec::new();
319318
self.add_existing_base_paths(lp, &mut result);
320319
result
321320
}
322321

323322
fn add_existing_base_paths(&self,
324323
lp: @LoanPath,
325-
result: &mut OptVec<MovePathIndex>) {
324+
result: &mut Vec<MovePathIndex>) {
326325
/*!
327326
* Adds any existing move path indices for `lp` and any base
328327
* paths of `lp` to `result`, but does not add new move paths

src/librustc/middle/cfg/construct.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use middle::ty;
1515
use collections::HashMap;
1616
use syntax::ast;
1717
use syntax::ast_util;
18-
use syntax::opt_vec;
18+
19+
use std::vec_ng::Vec;
1920

2021
struct CFGBuilder {
2122
tcx: ty::ctxt,
@@ -471,7 +472,7 @@ impl CFGBuilder {
471472
fn add_contained_edge(&mut self,
472473
source: CFGIndex,
473474
target: CFGIndex) {
474-
let data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
475+
let data = CFGEdgeData {exiting_scopes: Vec::new()};
475476
self.graph.add_edge(source, target, data);
476477
}
477478

@@ -480,7 +481,7 @@ impl CFGBuilder {
480481
from_index: CFGIndex,
481482
to_loop: LoopScope,
482483
to_index: CFGIndex) {
483-
let mut data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
484+
let mut data = CFGEdgeData {exiting_scopes: Vec::new()};
484485
let mut scope_id = from_expr.id;
485486
while scope_id != to_loop.loop_id {
486487
data.exiting_scopes.push(scope_id);

src/librustc/middle/cfg/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use middle::ty;
2020
use middle::typeck;
2121
use collections::HashMap;
2222
use syntax::ast;
23-
use syntax::opt_vec::OptVec;
23+
24+
use std::vec_ng::Vec;
2425

2526
mod construct;
2627

@@ -36,7 +37,7 @@ pub struct CFGNodeData {
3637
}
3738

3839
pub struct CFGEdgeData {
39-
exiting_scopes: OptVec<ast::NodeId>
40+
exiting_scopes: Vec<ast::NodeId>
4041
}
4142

4243
pub type CFGIndex = graph::NodeIndex;

src/librustc/middle/kind.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use util::ppaux::UserString;
1919
use syntax::ast::*;
2020
use syntax::attr;
2121
use syntax::codemap::Span;
22-
use syntax::opt_vec;
2322
use syntax::print::pprust::expr_to_str;
2423
use syntax::{visit,ast_util};
2524
use syntax::visit::Visitor;
@@ -50,6 +49,8 @@ use syntax::visit::Visitor;
5049
// primitives in the stdlib are explicitly annotated to only take sendable
5150
// types.
5251

52+
use std::vec_ng::Vec;
53+
5354
#[deriving(Clone)]
5455
pub struct Context {
5556
tcx: ty::ctxt,
@@ -92,7 +93,7 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
9293
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
9394
if !struct_tpt.generics.has_type_params() {
9495
let struct_ty = ty::mk_struct(cx.tcx, struct_did, ty::substs {
95-
regions: ty::NonerasedRegions(opt_vec::Empty),
96+
regions: ty::NonerasedRegions(Vec::new()),
9697
self_ty: None,
9798
tps: ~[]
9899
});

src/librustc/middle/privacy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! which are available for use externally when compiled as a library.
1414
1515
use std::mem::replace;
16+
use std::vec_ng::Vec;
1617
use collections::{HashSet, HashMap};
1718

1819
use metadata::csearch;
@@ -28,7 +29,6 @@ use syntax::ast_util::{is_local, def_id_of_def, local_def};
2829
use syntax::attr;
2930
use syntax::codemap::Span;
3031
use syntax::parse::token;
31-
use syntax::opt_vec;
3232
use syntax::visit;
3333
use syntax::visit::Visitor;
3434

@@ -855,8 +855,8 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
855855
debug!("privacy - list {}", pid.node.id);
856856
let seg = ast::PathSegment {
857857
identifier: pid.node.name,
858-
lifetimes: opt_vec::Empty,
859-
types: opt_vec::Empty,
858+
lifetimes: Vec::new(),
859+
types: Vec::new(),
860860
};
861861
let segs = vec!(seg);
862862
let path = ast::Path {

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ use syntax::parse::token::special_idents;
2525
use syntax::parse::token;
2626
use syntax::print::pprust::path_to_str;
2727
use syntax::codemap::{Span, DUMMY_SP, Pos};
28-
use syntax::opt_vec::OptVec;
2928
use syntax::visit;
3029
use syntax::visit::Visitor;
3130

3231
use std::cell::{Cell, RefCell};
3332
use std::uint;
33+
use std::vec_ng::Vec;
3434
use std::mem::replace;
3535
use collections::{HashMap, HashSet};
3636

@@ -3966,7 +3966,7 @@ impl Resolver {
39663966
}
39673967

39683968
fn resolve_type_parameters(&mut self,
3969-
type_parameters: &OptVec<TyParam>) {
3969+
type_parameters: &Vec<TyParam>) {
39703970
for type_parameter in type_parameters.iter() {
39713971
for bound in type_parameter.bounds.iter() {
39723972
self.resolve_type_parameter_bound(type_parameter.id, bound);

src/librustc/middle/resolve_lifetime.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
use driver::session;
2121
use std::cell::RefCell;
22+
use std::vec_ng::Vec;
23+
2224
use collections::HashMap;
2325
use syntax::ast;
2426
use syntax::codemap::Span;
25-
use syntax::opt_vec::OptVec;
2627
use syntax::parse::token::special_idents;
2728
use syntax::parse::token;
2829
use syntax::print::pprust::{lifetime_to_str};
@@ -39,8 +40,8 @@ struct LifetimeContext {
3940
}
4041

4142
enum ScopeChain<'a> {
42-
ItemScope(&'a OptVec<ast::Lifetime>),
43-
FnScope(ast::NodeId, &'a OptVec<ast::Lifetime>, &'a ScopeChain<'a>),
43+
ItemScope(&'a Vec<ast::Lifetime>),
44+
FnScope(ast::NodeId, &'a Vec<ast::Lifetime>, &'a ScopeChain<'a>),
4445
BlockScope(ast::NodeId, &'a ScopeChain<'a>),
4546
RootScope
4647
}
@@ -265,7 +266,7 @@ impl LifetimeContext {
265266
token::get_name(lifetime_ref.ident)));
266267
}
267268

268-
fn check_lifetime_names(&self, lifetimes: &OptVec<ast::Lifetime>) {
269+
fn check_lifetime_names(&self, lifetimes: &Vec<ast::Lifetime>) {
269270
for i in range(0, lifetimes.len()) {
270271
let lifetime_i = lifetimes.get(i);
271272

@@ -311,7 +312,7 @@ impl LifetimeContext {
311312
}
312313
}
313314

314-
fn search_lifetimes(lifetimes: &OptVec<ast::Lifetime>,
315+
fn search_lifetimes(lifetimes: &Vec<ast::Lifetime>,
315316
lifetime_ref: &ast::Lifetime)
316317
-> Option<(uint, ast::NodeId)> {
317318
for (i, lifetime_decl) in lifetimes.iter().enumerate() {

src/librustc/middle/subst.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use middle::ty_fold::TypeFolder;
1616
use util::ppaux::Repr;
1717

1818
use std::rc::Rc;
19+
use std::vec_ng::Vec;
1920
use syntax::codemap::Span;
20-
use syntax::opt_vec::OptVec;
2121

2222
///////////////////////////////////////////////////////////////////////////
2323
// Public trait `Subst`
@@ -145,10 +145,10 @@ impl<T:Subst> Subst for Rc<T> {
145145
}
146146
}
147147

148-
impl<T:Subst> Subst for OptVec<T> {
148+
impl<T:Subst> Subst for Vec<T> {
149149
fn subst_spanned(&self, tcx: ty::ctxt,
150150
substs: &ty::substs,
151-
span: Option<Span>) -> OptVec<T> {
151+
span: Option<Span>) -> Vec<T> {
152152
self.map(|t| t.subst_spanned(tcx, substs, span))
153153
}
154154
}

src/librustc/middle/trans/cleanup.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ use middle::trans::glue;
2424
use middle::trans::type_::Type;
2525
use middle::ty;
2626
use syntax::ast;
27-
use syntax::opt_vec;
28-
use syntax::opt_vec::OptVec;
2927
use util::ppaux::Repr;
3028

29+
use std::vec_ng::Vec;
30+
3131
pub struct CleanupScope<'a> {
3232
// The id of this cleanup scope. If the id is None,
3333
// this is a *temporary scope* that is pushed during trans to
@@ -37,9 +37,9 @@ pub struct CleanupScope<'a> {
3737
kind: CleanupScopeKind<'a>,
3838

3939
// Cleanups to run upon scope exit.
40-
cleanups: OptVec<~Cleanup>,
40+
cleanups: Vec<~Cleanup>,
4141

42-
cached_early_exits: OptVec<CachedEarlyExit>,
42+
cached_early_exits: Vec<CachedEarlyExit>,
4343
cached_landing_pad: Option<BasicBlockRef>,
4444
}
4545

@@ -379,7 +379,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
379379
assert!(orig_scopes_len > 0);
380380

381381
// Remove any scopes that do not have cleanups on failure:
382-
let mut popped_scopes = opt_vec::Empty;
382+
let mut popped_scopes = Vec::new();
383383
while !self.top_scope(|s| s.needs_invoke()) {
384384
debug!("top scope does not need invoke");
385385
popped_scopes.push(self.pop_scope());
@@ -510,7 +510,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
510510

511511
let orig_scopes_len = self.scopes_len();
512512
let mut prev_llbb;
513-
let mut popped_scopes = opt_vec::Empty;
513+
let mut popped_scopes = Vec::new();
514514

515515
// First we pop off all the cleanup stacks that are
516516
// traversed until the exit is reached, pushing them
@@ -706,14 +706,14 @@ impl<'a> CleanupScope<'a> {
706706
fn new(kind: CleanupScopeKind<'a>) -> CleanupScope<'a> {
707707
CleanupScope {
708708
kind: kind,
709-
cleanups: opt_vec::Empty,
710-
cached_early_exits: opt_vec::Empty,
709+
cleanups: Vec::new(),
710+
cached_early_exits: Vec::new(),
711711
cached_landing_pad: None,
712712
}
713713
}
714714

715715
fn clear_cached_exits(&mut self) {
716-
self.cached_early_exits = opt_vec::Empty;
716+
self.cached_early_exits = Vec::new();
717717
self.cached_landing_pad = None;
718718
}
719719

src/librustc/middle/trans/debuginfo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ use std::libc::{c_uint, c_ulonglong, c_longlong};
148148
use std::ptr;
149149
use std::sync::atomics;
150150
use std::vec;
151+
use std::vec_ng::Vec;
151152
use syntax::codemap::{Span, Pos};
152-
use syntax::{abi, ast, codemap, ast_util, ast_map, opt_vec};
153+
use syntax::{abi, ast, codemap, ast_util, ast_map};
153154
use syntax::parse::token;
154155
use syntax::parse::token::special_idents;
155156

@@ -538,7 +539,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
538539
return FunctionWithoutDebugInfo;
539540
}
540541

541-
let empty_generics = ast::Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty };
542+
let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: Vec::new() };
542543

543544
let fnitem = cx.tcx.map.get(fn_ast_id);
544545

0 commit comments

Comments
 (0)