Skip to content

Commit f5357cf

Browse files
committed
auto merge of #13016 : huonw/rust/new-opt-vec, r=cmr
Replace syntax::opt_vec with syntax::owned_slice The `owned_slice::OwnedSlice` is `(*T, uint)` (i.e. a direct equivalent to DSTs `~[T]`). This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)
2 parents bbf8cdc + e33676b commit f5357cf

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

+369
-451
lines changed

src/librustc/front/std_inject.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::codemap::DUMMY_SP;
1818
use syntax::codemap;
1919
use syntax::fold::Folder;
2020
use syntax::fold;
21-
use syntax::opt_vec;
21+
use syntax::owned_slice::OwnedSlice;
2222
use syntax::parse::token::InternedString;
2323
use syntax::parse::token;
2424
use syntax::util::small_vector::SmallVector;
@@ -156,12 +156,12 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
156156
ast::PathSegment {
157157
identifier: token::str_to_ident("std"),
158158
lifetimes: Vec::new(),
159-
types: opt_vec::Empty,
159+
types: OwnedSlice::empty(),
160160
},
161161
ast::PathSegment {
162162
identifier: token::str_to_ident("prelude"),
163163
lifetimes: Vec::new(),
164-
types: opt_vec::Empty,
164+
types: OwnedSlice::empty(),
165165
}),
166166
};
167167

src/librustc/front/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::ext::base::ExtCtxt;
3131
use syntax::ext::expand::ExpansionConfig;
3232
use syntax::fold::Folder;
3333
use syntax::fold;
34-
use syntax::opt_vec;
34+
use syntax::owned_slice::OwnedSlice;
3535
use syntax::parse::token::InternedString;
3636
use syntax::parse::token;
3737
use syntax::print::pprust;
@@ -377,7 +377,7 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
377377
segments: ids.move_iter().map(|identifier| ast::PathSegment {
378378
identifier: identifier,
379379
lifetimes: Vec::new(),
380-
types: opt_vec::Empty,
380+
types: OwnedSlice::empty(),
381381
}).collect()
382382
}
383383
}
@@ -389,7 +389,7 @@ fn path_node_global(ids: Vec<ast::Ident> ) -> ast::Path {
389389
segments: ids.move_iter().map(|identifier| ast::PathSegment {
390390
identifier: identifier,
391391
lifetimes: Vec::new(),
392-
types: opt_vec::Empty,
392+
types: OwnedSlice::empty(),
393393
}).collect()
394394
}
395395
}

src/librustc/metadata/tydecode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use syntax::abi::AbiSet;
2424
use syntax::abi;
2525
use syntax::ast;
2626
use syntax::ast::*;
27-
use syntax::opt_vec;
27+
use syntax::owned_slice::OwnedSlice;
2828
use syntax::parse::token;
2929

3030
// Compact string representation for ty::t values. API ty_str &
@@ -192,13 +192,13 @@ 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!();
196196
while peek(st) != '.' {
197197
let r = parse_region(st, |x,y| conv(x,y));
198198
regions.push(r);
199199
}
200200
assert_eq!(next(st), '.');
201-
ty::NonerasedRegions(regions)
201+
ty::NonerasedRegions(OwnedSlice::from_vec(regions))
202202
}
203203
_ => fail!("parse_bound_region: bad input")
204204
}

src/librustc/middle/borrowck/move_data.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ use middle::typeck;
2626
use syntax::ast;
2727
use syntax::ast_util;
2828
use syntax::codemap::Span;
29-
use syntax::opt_vec::OptVec;
30-
use syntax::opt_vec;
3129
use util::ppaux::Repr;
3230

3331
pub struct MoveData {
@@ -316,15 +314,15 @@ impl MoveData {
316314

317315
fn existing_base_paths(&self,
318316
lp: @LoanPath)
319-
-> OptVec<MovePathIndex> {
320-
let mut result = opt_vec::Empty;
317+
-> Vec<MovePathIndex> {
318+
let mut result = vec!();
321319
self.add_existing_base_paths(lp, &mut result);
322320
result
323321
}
324322

325323
fn add_existing_base_paths(&self,
326324
lp: @LoanPath,
327-
result: &mut OptVec<MovePathIndex>) {
325+
result: &mut Vec<MovePathIndex>) {
328326
/*!
329327
* Adds any existing move path indices for `lp` and any base
330328
* paths of `lp` to `result`, but does not add new move paths

src/librustc/middle/cfg/construct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use middle::typeck;
1414
use middle::ty;
1515
use syntax::ast;
1616
use syntax::ast_util;
17-
use syntax::opt_vec;
1817
use util::nodemap::NodeMap;
1918

2019
struct CFGBuilder<'a> {
@@ -470,7 +469,7 @@ impl<'a> CFGBuilder<'a> {
470469
fn add_contained_edge(&mut self,
471470
source: CFGIndex,
472471
target: CFGIndex) {
473-
let data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
472+
let data = CFGEdgeData {exiting_scopes: vec!() };
474473
self.graph.add_edge(source, target, data);
475474
}
476475

@@ -479,9 +478,10 @@ impl<'a> CFGBuilder<'a> {
479478
from_index: CFGIndex,
480479
to_loop: LoopScope,
481480
to_index: CFGIndex) {
482-
let mut data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
481+
let mut data = CFGEdgeData {exiting_scopes: vec!() };
483482
let mut scope_id = from_expr.id;
484483
while scope_id != to_loop.loop_id {
484+
485485
data.exiting_scopes.push(scope_id);
486486
scope_id = self.tcx.region_maps.encl_scope(scope_id);
487487
}

src/librustc/middle/cfg/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use middle::graph;
1919
use middle::ty;
2020
use middle::typeck;
2121
use syntax::ast;
22-
use syntax::opt_vec::OptVec;
2322
use util::nodemap::NodeMap;
2423

2524
mod construct;
@@ -36,7 +35,7 @@ pub struct CFGNodeData {
3635
}
3736

3837
pub struct CFGEdgeData {
39-
exiting_scopes: OptVec<ast::NodeId>
38+
exiting_scopes: Vec<ast::NodeId>
4039
}
4140

4241
pub type CFGIndex = graph::NodeIndex;

src/librustc/middle/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use util::ppaux::UserString;
1919
use syntax::ast::*;
2020
use syntax::attr;
2121
use syntax::codemap::Span;
22-
use syntax::opt_vec;
22+
use syntax::owned_slice::OwnedSlice;
2323
use syntax::print::pprust::expr_to_str;
2424
use syntax::{visit,ast_util};
2525
use syntax::visit::Visitor;
@@ -92,7 +92,7 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
9292
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
9393
if !struct_tpt.generics.has_type_params() {
9494
let struct_ty = ty::mk_struct(cx.tcx, struct_did, ty::substs {
95-
regions: ty::NonerasedRegions(opt_vec::Empty),
95+
regions: ty::NonerasedRegions(OwnedSlice::empty()),
9696
self_ty: None,
9797
tps: Vec::new()
9898
});

src/librustc/middle/privacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use syntax::ast_util::{is_local, def_id_of_def, local_def};
2828
use syntax::attr;
2929
use syntax::codemap::Span;
3030
use syntax::parse::token;
31-
use syntax::opt_vec;
31+
use syntax::owned_slice::OwnedSlice;
3232
use syntax::visit;
3333
use syntax::visit::Visitor;
3434

@@ -842,7 +842,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
842842
let seg = ast::PathSegment {
843843
identifier: pid.node.name,
844844
lifetimes: Vec::new(),
845-
types: opt_vec::Empty,
845+
types: OwnedSlice::empty(),
846846
};
847847
let segs = vec!(seg);
848848
let path = ast::Path {

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax::parse::token::special_idents;
2727
use syntax::parse::token;
2828
use syntax::print::pprust::path_to_str;
2929
use syntax::codemap::{Span, DUMMY_SP, Pos};
30-
use syntax::opt_vec::OptVec;
30+
use syntax::owned_slice::OwnedSlice;
3131
use syntax::visit;
3232
use syntax::visit::Visitor;
3333

@@ -3969,7 +3969,7 @@ impl<'a> Resolver<'a> {
39693969
}
39703970

39713971
fn resolve_type_parameters(&mut self,
3972-
type_parameters: &OptVec<TyParam>) {
3972+
type_parameters: &OwnedSlice<TyParam>) {
39733973
for type_parameter in type_parameters.iter() {
39743974
for bound in type_parameter.bounds.iter() {
39753975
self.resolve_type_parameter_bound(type_parameter.id, bound);

src/librustc/middle/resolve_lifetime.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use driver::session::Session;
2121
use util::nodemap::NodeMap;
2222
use syntax::ast;
2323
use syntax::codemap::Span;
24-
use syntax::opt_vec;
25-
use syntax::opt_vec::OptVec;
24+
use syntax::owned_slice::OwnedSlice;
2625
use syntax::parse::token::special_idents;
2726
use syntax::parse::token;
2827
use syntax::print::pprust::{lifetime_to_str};
@@ -413,22 +412,22 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti
413412
.collect()
414413
}
415414

416-
pub fn free_lifetimes(ty_params: &OptVec<ast::TyParam>) -> OptVec<ast::Name> {
415+
pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>) -> Vec<ast::Name> {
417416
/*!
418417
* Gathers up and returns the names of any lifetimes that appear
419418
* free in `ty_params`. Of course, right now, all lifetimes appear
420419
* free, since we don't currently have any binders in type parameter
421420
* declarations; just being forwards compatible with future extensions.
422421
*/
423422

424-
let mut collector = FreeLifetimeCollector { names: opt_vec::Empty };
423+
let mut collector = FreeLifetimeCollector { names: vec!() };
425424
for ty_param in ty_params.iter() {
426425
visit::walk_ty_param_bounds(&mut collector, &ty_param.bounds, ());
427426
}
428427
return collector.names;
429428

430429
struct FreeLifetimeCollector {
431-
names: OptVec<ast::Name>,
430+
names: Vec<ast::Name>,
432431
}
433432

434433
impl Visitor<()> for FreeLifetimeCollector {

0 commit comments

Comments
 (0)