Skip to content

Commit c4c2370

Browse files
---
yaml --- r: 147261 b: refs/heads/try2 c: ae66285 h: refs/heads/master i: 147259: ccc35e9 v: v3
1 parent 323ec86 commit c4c2370

File tree

7 files changed

+53
-63
lines changed

7 files changed

+53
-63
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 7b424974531b0ade62e6a26cce038abf5dac0723
8+
refs/heads/try2: ae6628573282855a9b93de266add64c69411b0b0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/dead.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ impl MarkSymbolVisitor {
107107
match item.node {
108108
ast::item_fn(..)
109109
| ast::item_ty(..)
110-
| ast::item_enum(..)
111-
| ast::item_struct(..)
112110
| ast::item_static(..) => {
113111
visit::walk_item(self, item, ());
114112
}

branches/try2/src/librustc/middle/trans/debuginfo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,8 @@ fn set_debug_location(cx: &mut CrateContext, debug_location: DebugLocation) {
21282128
let metadata_node;
21292129

21302130
match debug_location {
2131-
KnownLocation { scope, line, col } => {
2131+
KnownLocation { scope, line, .. } => {
2132+
let col = 0; // Always set the column to zero like Clang and GCC
21322133
debug!("setting debug location to {} {}", line, col);
21332134
let elements = [C_i32(line as i32), C_i32(col as i32), scope, ptr::null()];
21342135
unsafe {

branches/try2/src/libstd/hashmap.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
157157
vec::from_fn(new_capacity, |_| None));
158158

159159
self.size = 0;
160-
for bucket in old_buckets.move_iter() {
160+
// move_rev_iter is more efficient
161+
for bucket in old_buckets.move_rev_iter() {
161162
self.insert_opt_bucket(bucket);
162163
}
163164
}
@@ -476,7 +477,8 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
476477
/// pair out of the map in arbitrary order. The map cannot be used after
477478
/// calling this.
478479
pub fn move_iter(self) -> HashMapMoveIterator<K, V> {
479-
HashMapMoveIterator {iter: self.buckets.move_iter()}
480+
// `move_rev_iter` is more efficient than `move_iter` for vectors
481+
HashMapMoveIterator {iter: self.buckets.move_rev_iter()}
480482
}
481483
}
482484

@@ -530,7 +532,7 @@ pub struct HashMapMutIterator<'a, K, V> {
530532

531533
/// HashMap move iterator
532534
pub struct HashMapMoveIterator<K, V> {
533-
priv iter: vec::MoveIterator<Option<Bucket<K, V>>>,
535+
priv iter: vec::MoveRevIterator<Option<Bucket<K, V>>>,
534536
}
535537

536538
/// HashSet iterator
@@ -541,7 +543,7 @@ pub struct HashSetIterator<'a, K> {
541543

542544
/// HashSet move iterator
543545
pub struct HashSetMoveIterator<K> {
544-
priv iter: vec::MoveIterator<Option<Bucket<K, ()>>>,
546+
priv iter: vec::MoveRevIterator<Option<Bucket<K, ()>>>,
545547
}
546548

547549
impl<'a, K, V> Iterator<(&'a K, &'a V)> for HashMapIterator<'a, K, V> {
@@ -727,7 +729,8 @@ impl<T:Hash + Eq> HashSet<T> {
727729
/// of the set in arbitrary order. The set cannot be used after calling
728730
/// this.
729731
pub fn move_iter(self) -> HashSetMoveIterator<T> {
730-
HashSetMoveIterator {iter: self.map.buckets.move_iter()}
732+
// `move_rev_iter` is more efficient than `move_iter` for vectors
733+
HashSetMoveIterator {iter: self.map.buckets.move_rev_iter()}
731734
}
732735

733736
/// Visit the values representing the difference

branches/try2/src/libstd/vec.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,20 @@ There are a number of free functions that create or take vectors, for example:
102102
#[warn(non_camel_case_types)];
103103

104104
use cast;
105-
use ops::Drop;
106105
use clone::{Clone, DeepClone};
107106
use container::{Container, Mutable};
108107
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
109108
use cmp;
110109
use default::Default;
111110
use iter::*;
112-
use libc::{c_char, c_void};
111+
use libc::c_void;
113112
use num::{Integer, CheckedAdd, Saturating};
114113
use option::{None, Option, Some};
115114
use ptr::to_unsafe_ptr;
116115
use ptr;
117116
use ptr::RawPtr;
118-
use rt::global_heap::{malloc_raw, realloc_raw, exchange_free};
119-
use rt::local_heap::local_free;
117+
use rt::global_heap::malloc_raw;
118+
use rt::global_heap::realloc_raw;
120119
use mem;
121120
use mem::size_of;
122121
use uint;
@@ -1326,6 +1325,9 @@ pub trait OwnedVector<T> {
13261325
/// value out of the vector (from start to end). The vector cannot
13271326
/// be used after calling this.
13281327
///
1328+
/// Note that this performs O(n) swaps, and so `move_rev_iter`
1329+
/// (which just calls `pop` repeatedly) is more efficient.
1330+
///
13291331
/// # Examples
13301332
///
13311333
/// ```rust
@@ -1337,7 +1339,8 @@ pub trait OwnedVector<T> {
13371339
/// ```
13381340
fn move_iter(self) -> MoveIterator<T>;
13391341
/// Creates a consuming iterator that moves out of the vector in
1340-
/// reverse order.
1342+
/// reverse order. Also see `move_iter`, however note that this
1343+
/// is more efficient.
13411344
fn move_rev_iter(self) -> MoveRevIterator<T>;
13421345

13431346
/**
@@ -1466,18 +1469,11 @@ pub trait OwnedVector<T> {
14661469
}
14671470

14681471
impl<T> OwnedVector<T> for ~[T] {
1469-
#[inline]
14701472
fn move_iter(self) -> MoveIterator<T> {
1471-
unsafe {
1472-
let iter = cast::transmute(self.iter());
1473-
let ptr = cast::transmute(self);
1474-
MoveIterator { allocation: ptr, iter: iter }
1475-
}
1473+
MoveIterator { v: self, idx: 0 }
14761474
}
1477-
1478-
#[inline]
14791475
fn move_rev_iter(self) -> MoveRevIterator<T> {
1480-
self.move_iter().invert()
1476+
MoveRevIterator { v: self }
14811477
}
14821478

14831479
fn reserve(&mut self, n: uint) {
@@ -2664,54 +2660,58 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunkIter<'a, T> {
26642660
}
26652661

26662662
/// An iterator that moves out of a vector.
2663+
#[deriving(Clone)]
26672664
pub struct MoveIterator<T> {
2668-
priv allocation: *mut u8, // the block of memory allocated for the vector
2669-
priv iter: VecIterator<'static, T>
2665+
priv v: ~[T],
2666+
priv idx: uint,
26702667
}
26712668

26722669
impl<T> Iterator<T> for MoveIterator<T> {
26732670
#[inline]
26742671
fn next(&mut self) -> Option<T> {
2675-
unsafe {
2676-
self.iter.next().map(|x| ptr::read_ptr(x))
2672+
// this is peculiar, but is required for safety with respect
2673+
// to dtors. It traverses the first half of the vec, and
2674+
// removes them by swapping them with the last element (and
2675+
// popping), which results in the second half in reverse
2676+
// order, and so these can just be pop'd off. That is,
2677+
//
2678+
// [1,2,3,4,5] => 1, [5,2,3,4] => 2, [5,4,3] => 3, [5,4] => 4,
2679+
// [5] -> 5, []
2680+
let l = self.v.len();
2681+
if self.idx < l {
2682+
self.v.swap(self.idx, l - 1);
2683+
self.idx += 1;
26772684
}
2685+
2686+
self.v.pop_opt()
26782687
}
26792688

26802689
#[inline]
26812690
fn size_hint(&self) -> (uint, Option<uint>) {
2682-
self.iter.size_hint()
2691+
let l = self.v.len();
2692+
(l, Some(l))
26832693
}
26842694
}
26852695

2686-
impl<T> DoubleEndedIterator<T> for MoveIterator<T> {
2696+
/// An iterator that moves out of a vector in reverse order.
2697+
#[deriving(Clone)]
2698+
pub struct MoveRevIterator<T> {
2699+
priv v: ~[T]
2700+
}
2701+
2702+
impl<T> Iterator<T> for MoveRevIterator<T> {
26872703
#[inline]
2688-
fn next_back(&mut self) -> Option<T> {
2689-
unsafe {
2690-
self.iter.next_back().map(|x| ptr::read_ptr(x))
2691-
}
2704+
fn next(&mut self) -> Option<T> {
2705+
self.v.pop_opt()
26922706
}
2693-
}
26942707

2695-
#[unsafe_destructor]
2696-
impl<T> Drop for MoveIterator<T> {
2697-
fn drop(&mut self) {
2698-
unsafe {
2699-
// destroy the remaining elements
2700-
for x in self.iter {
2701-
ptr::read_ptr(x);
2702-
}
2703-
if owns_managed::<T>() {
2704-
local_free(self.allocation as *u8 as *c_char)
2705-
} else {
2706-
exchange_free(self.allocation as *u8 as *c_char)
2707-
}
2708-
}
2708+
#[inline]
2709+
fn size_hint(&self) -> (uint, Option<uint>) {
2710+
let l = self.v.len();
2711+
(l, Some(l))
27092712
}
27102713
}
27112714

2712-
/// An iterator that moves out of a vector in reverse order.
2713-
pub type MoveRevIterator<T> = Invert<MoveIterator<T>>;
2714-
27152715
impl<A> FromIterator<A> for ~[A] {
27162716
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
27172717
let (lower, _) = iterator.size_hint();

branches/try2/src/libsyntax/visit.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@ pub fn walk_variant<E:Clone, V:Visitor<E>>(visitor:&mut V,
290290
env.clone())
291291
}
292292
}
293-
match variant.node.disr_expr {
294-
Some(expr) => visitor.visit_expr(expr, env),
295-
None => ()
296-
}
297293
}
298294

299295
pub fn skip_ty<E, V:Visitor<E>>(_: &mut V, _: &Ty, _: E) {

branches/try2/src/test/compile-fail/lint-dead-code-1.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ static priv_static: int = 0; //~ ERROR: code is never used
2727
static used_static: int = 0;
2828
pub static used_static2: int = used_static;
2929
static USED_STATIC: int = 0;
30-
static STATIC_USED_IN_ENUM_DISCRIMINANT: uint = 10;
3130

3231
pub type typ = ~UsedStruct4;
3332
pub struct PubStruct();
@@ -42,15 +41,8 @@ struct SemiUsedStruct;
4241
impl SemiUsedStruct {
4342
fn la_la_la() {}
4443
}
45-
struct StructUsedAsField;
46-
struct StructUsedInEnum;
47-
pub struct PubStruct2 {
48-
struct_used_as_field: *StructUsedAsField
49-
}
5044

5145
pub enum pub_enum { foo1, bar1 }
52-
pub enum pub_enum2 { a(~StructUsedInEnum) }
53-
pub enum pub_enum3 { Foo = STATIC_USED_IN_ENUM_DISCRIMINANT }
5446
enum priv_enum { foo2, bar2 } //~ ERROR: code is never used
5547
enum used_enum { foo3, bar3 }
5648

0 commit comments

Comments
 (0)