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() {

0 commit comments

Comments
 (0)