Skip to content

Commit d0b3956

Browse files
committed
---
yaml --- r: 178814 b: refs/heads/tmp c: 74f7e06 h: refs/heads/master v: v3
1 parent 4397a19 commit d0b3956

File tree

50 files changed

+5381
-70
lines changed

Some content is hidden

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

50 files changed

+5381
-70
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 8ddcb06b1d021560bfe641c0dbc452a04e80388e
37+
refs/heads/tmp: 74f7e0693909a45f9159c6d2ef72b42fcb4f1bac

branches/tmp/src/libcollections/vec_map.rs

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
1414
#![allow(missing_docs)]
1515

16+
pub use self::Entry::*;
17+
1618
use core::prelude::*;
1719

1820
use core::cmp::Ordering;
@@ -66,6 +68,32 @@ pub struct VecMap<V> {
6668
v: Vec<Option<V>>,
6769
}
6870

71+
/// A view into a single entry in a map, which may either be vacant or occupied.
72+
#[unstable(feature = "collections",
73+
reason = "precise API still under development")]
74+
pub enum Entry<'a, V:'a> {
75+
/// A vacant Entry
76+
Vacant(VacantEntry<'a, V>),
77+
/// An occupied Entry
78+
Occupied(OccupiedEntry<'a, V>),
79+
}
80+
81+
/// A vacant Entry.
82+
#[unstable(feature = "collections",
83+
reason = "precise API still under development")]
84+
pub struct VacantEntry<'a, V:'a> {
85+
map: &'a mut VecMap<V>,
86+
index: usize,
87+
}
88+
89+
/// An occupied Entry.
90+
#[unstable(feature = "collections",
91+
reason = "precise API still under development")]
92+
pub struct OccupiedEntry<'a, V:'a> {
93+
map: &'a mut VecMap<V>,
94+
index: usize,
95+
}
96+
6997
#[stable(feature = "rust1", since = "1.0.0")]
7098
impl<V> Default for VecMap<V> {
7199
#[stable(feature = "rust1", since = "1.0.0")]
@@ -485,6 +513,119 @@ impl<V> VecMap<V> {
485513
let result = &mut self.v[*key];
486514
result.take()
487515
}
516+
517+
/// Gets the given key's corresponding entry in the map for in-place manipulation.
518+
///
519+
/// # Examples
520+
///
521+
/// ```
522+
/// use std::collections::VecMap;
523+
/// use std::collections::vec_map::Entry;
524+
///
525+
/// let mut count: VecMap<u32> = VecMap::new();
526+
///
527+
/// // count the number of occurrences of numbers in the vec
528+
/// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4].iter() {
529+
/// match count.entry(*x) {
530+
/// Entry::Vacant(view) => {
531+
/// view.insert(1);
532+
/// },
533+
/// Entry::Occupied(mut view) => {
534+
/// let v = view.get_mut();
535+
/// *v += 1;
536+
/// },
537+
/// }
538+
/// }
539+
///
540+
/// assert_eq!(count[1], 3);
541+
/// ```
542+
#[unstable(feature = "collections",
543+
reason = "precise API still under development")]
544+
pub fn entry(&mut self, key: usize) -> Entry<V> {
545+
// FIXME(Gankro): this is basically the dumbest implementation of
546+
// entry possible, because weird non-lexical borrows issues make it
547+
// completely insane to do any other way. That said, Entry is a border-line
548+
// useless construct on VecMap, so it's hardly a big loss.
549+
if self.contains_key(&key) {
550+
Occupied(OccupiedEntry {
551+
map: self,
552+
index: key,
553+
})
554+
} else {
555+
Vacant(VacantEntry {
556+
map: self,
557+
index: key,
558+
})
559+
}
560+
}
561+
}
562+
563+
564+
impl<'a, V> Entry<'a, V> {
565+
#[unstable(feature = "collections",
566+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
567+
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
568+
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
569+
match self {
570+
Occupied(entry) => Ok(entry.into_mut()),
571+
Vacant(entry) => Err(entry),
572+
}
573+
}
574+
}
575+
576+
impl<'a, V> VacantEntry<'a, V> {
577+
/// Sets the value of the entry with the VacantEntry's key,
578+
/// and returns a mutable reference to it.
579+
#[unstable(feature = "collections",
580+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
581+
pub fn insert(self, value: V) -> &'a mut V {
582+
let index = self.index;
583+
self.map.insert(index, value);
584+
&mut self.map[index]
585+
}
586+
}
587+
588+
impl<'a, V> OccupiedEntry<'a, V> {
589+
/// Gets a reference to the value in the entry.
590+
#[unstable(feature = "collections",
591+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
592+
pub fn get(&self) -> &V {
593+
let index = self.index;
594+
&self.map[index]
595+
}
596+
597+
/// Gets a mutable reference to the value in the entry.
598+
#[unstable(feature = "collections",
599+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
600+
pub fn get_mut(&mut self) -> &mut V {
601+
let index = self.index;
602+
&mut self.map[index]
603+
}
604+
605+
/// Converts the entry into a mutable reference to its value.
606+
#[unstable(feature = "collections",
607+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
608+
pub fn into_mut(self) -> &'a mut V {
609+
let index = self.index;
610+
&mut self.map[index]
611+
}
612+
613+
/// Sets the value of the entry with the OccupiedEntry's key,
614+
/// and returns the entry's old value.
615+
#[unstable(feature = "collections",
616+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
617+
pub fn insert(&mut self, value: V) -> V {
618+
let index = self.index;
619+
self.map.insert(index, value).unwrap()
620+
}
621+
622+
/// Takes the value of the entry out of the map, and returns it.
623+
#[unstable(feature = "collections",
624+
reason = "matches collection reform v2 specification, waiting for dust to settle")]
625+
pub fn remove(self) -> V {
626+
let index = self.index;
627+
self.map.remove(&index).unwrap()
628+
}
488629
}
489630

490631
#[stable(feature = "rust1", since = "1.0.0")]
@@ -783,7 +924,7 @@ mod test_map {
783924
use prelude::*;
784925
use core::hash::{hash, SipHasher};
785926

786-
use super::VecMap;
927+
use super::{VecMap, Occupied, Vacant};
787928

788929
#[test]
789930
fn test_get_mut() {
@@ -1135,6 +1276,57 @@ mod test_map {
11351276

11361277
map[4];
11371278
}
1279+
1280+
#[test]
1281+
fn test_entry(){
1282+
let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)];
1283+
1284+
let mut map: VecMap<i32> = xs.iter().map(|&x| x).collect();
1285+
1286+
// Existing key (insert)
1287+
match map.entry(1) {
1288+
Vacant(_) => unreachable!(),
1289+
Occupied(mut view) => {
1290+
assert_eq!(view.get(), &10);
1291+
assert_eq!(view.insert(100), 10);
1292+
}
1293+
}
1294+
assert_eq!(map.get(&1).unwrap(), &100);
1295+
assert_eq!(map.len(), 6);
1296+
1297+
1298+
// Existing key (update)
1299+
match map.entry(2) {
1300+
Vacant(_) => unreachable!(),
1301+
Occupied(mut view) => {
1302+
let v = view.get_mut();
1303+
*v *= 10;
1304+
}
1305+
}
1306+
assert_eq!(map.get(&2).unwrap(), &200);
1307+
assert_eq!(map.len(), 6);
1308+
1309+
// Existing key (take)
1310+
match map.entry(3) {
1311+
Vacant(_) => unreachable!(),
1312+
Occupied(view) => {
1313+
assert_eq!(view.remove(), 30);
1314+
}
1315+
}
1316+
assert_eq!(map.get(&3), None);
1317+
assert_eq!(map.len(), 5);
1318+
1319+
1320+
// Inexistent key (insert)
1321+
match map.entry(10) {
1322+
Occupied(_) => unreachable!(),
1323+
Vacant(view) => {
1324+
assert_eq!(*view.insert(1000), 1000);
1325+
}
1326+
}
1327+
assert_eq!(map.get(&10).unwrap(), &1000);
1328+
assert_eq!(map.len(), 6);
1329+
}
11381330
}
11391331

11401332
#[cfg(test)]

branches/tmp/src/libcore/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//! use std::error::FromError;
5252
//! use std::old_io::{File, IoError};
5353
//! use std::os::{MemoryMap, MapError};
54-
//! use std::path::Path;
54+
//! use std::old_path::Path;
5555
//!
5656
//! enum MyError {
5757
//! Io(IoError),

branches/tmp/src/libcore/fmt/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ pub trait Show {
264264
#[lang = "debug_trait"]
265265
pub trait Debug {
266266
/// Formats the value using the given formatter.
267+
#[stable(feature = "rust1", since = "1.0.0")]
267268
fn fmt(&self, &mut Formatter) -> Result;
268269
}
269270

@@ -290,6 +291,7 @@ pub trait String {
290291
#[stable(feature = "rust1", since = "1.0.0")]
291292
pub trait Display {
292293
/// Formats the value using the given formatter.
294+
#[stable(feature = "rust1", since = "1.0.0")]
293295
fn fmt(&self, &mut Formatter) -> Result;
294296
}
295297

branches/tmp/src/libcore/iter.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl<'a, T> Iterator for &'a mut (Iterator<Item=T> + 'a) {
119119
built from an iterator over elements of type `{A}`"]
120120
pub trait FromIterator<A> {
121121
/// Build a container with elements from an external iterator.
122+
#[stable(feature = "rust1", since = "1.0.0")]
122123
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> Self;
123124
}
124125

@@ -723,11 +724,12 @@ pub trait IteratorExt: Iterator + Sized {
723724
P: FnMut(Self::Item) -> bool,
724725
Self: ExactSizeIterator + DoubleEndedIterator
725726
{
726-
let len = self.len();
727-
for i in (0..len).rev() {
728-
if predicate(self.next_back().expect("rposition: incorrect ExactSizeIterator")) {
727+
let mut i = self.len() - 1;
728+
while let Some(v) = self.next_back() {
729+
if predicate(v) {
729730
return Some(i);
730731
}
732+
i -= 1;
731733
}
732734
None
733735
}
@@ -1821,6 +1823,7 @@ impl<I: Iterator> Peekable<I> {
18211823
/// Return a reference to the next element of the iterator with out
18221824
/// advancing it, or None if the iterator is exhausted.
18231825
#[inline]
1826+
#[stable(feature = "rust1", since = "1.0.0")]
18241827
pub fn peek(&mut self) -> Option<&I::Item> {
18251828
if self.peeked.is_none() {
18261829
self.peeked = self.iter.next();

branches/tmp/src/libgraphviz/maybe_owned_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::cmp::Ordering;
1717
use std::default::Default;
1818
use std::fmt;
1919
use std::iter::FromIterator;
20-
use std::path::BytesContainer;
20+
use std::old_path::BytesContainer;
2121
use std::slice;
2222

2323
// Note 1: It is not clear whether the flexibility of providing both

branches/tmp/src/librustc_back/target/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl Target {
306306
use std::env;
307307
use std::ffi::OsString;
308308
use std::old_io::File;
309-
use std::path::Path;
309+
use std::old_path::Path;
310310
use serialize::json;
311311

312312
fn load_file(path: &Path) -> Result<Target, String> {

branches/tmp/src/librustc_trans/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
15901590
Some(ref p) if p.is_relative() => {
15911591
// prepend "./" if necessary
15921592
let dotdot = b"..";
1593-
let prefix: &[u8] = &[dotdot[0], ::std::path::SEP_BYTE];
1593+
let prefix: &[u8] = &[dotdot[0], ::std::old_path::SEP_BYTE];
15941594
let mut path_bytes = p.as_vec().to_vec();
15951595

15961596
if &path_bytes[..2] != prefix &&

branches/tmp/src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
194194
// a different region or mutability, but we don't care here. It might
195195
// also be just in case we need to unsize. But if there are no nested
196196
// adjustments then it should be a no-op).
197-
Some(ty::AutoPtr(_, _, None)) if adj.autoderefs == 1 => {
197+
Some(ty::AutoPtr(_, _, None)) |
198+
Some(ty::AutoUnsafe(_, None)) if adj.autoderefs == 1 => {
198199
match datum.ty.sty {
199200
// Don't skip a conversion from Box<T> to &T, etc.
200201
ty::ty_rptr(..) => {

branches/tmp/src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc::middle::stability;
4949
use std::rc::Rc;
5050
use std::u32;
5151
use std::str::Str as StrTrait; // Conflicts with Str variant
52-
use std::path::Path as FsPath; // Conflicts with Path struct
52+
use std::old_path::Path as FsPath; // Conflicts with Path struct
5353

5454
use core::DocContext;
5555
use doctree;

branches/tmp/src/libserialize/serialize.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Core encoding and decoding interfaces.
1515
*/
1616

17-
use std::path;
17+
use std::old_path;
1818
use std::rc::Rc;
1919
use std::cell::{Cell, RefCell};
2020
use std::sync::Arc;
@@ -538,29 +538,29 @@ macro_rules! tuple {
538538

539539
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
540540

541-
impl Encodable for path::posix::Path {
541+
impl Encodable for old_path::posix::Path {
542542
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
543543
self.as_vec().encode(e)
544544
}
545545
}
546546

547-
impl Decodable for path::posix::Path {
548-
fn decode<D: Decoder>(d: &mut D) -> Result<path::posix::Path, D::Error> {
547+
impl Decodable for old_path::posix::Path {
548+
fn decode<D: Decoder>(d: &mut D) -> Result<old_path::posix::Path, D::Error> {
549549
let bytes: Vec<u8> = try!(Decodable::decode(d));
550-
Ok(path::posix::Path::new(bytes))
550+
Ok(old_path::posix::Path::new(bytes))
551551
}
552552
}
553553

554-
impl Encodable for path::windows::Path {
554+
impl Encodable for old_path::windows::Path {
555555
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
556556
self.as_vec().encode(e)
557557
}
558558
}
559559

560-
impl Decodable for path::windows::Path {
561-
fn decode<D: Decoder>(d: &mut D) -> Result<path::windows::Path, D::Error> {
560+
impl Decodable for old_path::windows::Path {
561+
fn decode<D: Decoder>(d: &mut D) -> Result<old_path::windows::Path, D::Error> {
562562
let bytes: Vec<u8> = try!(Decodable::decode(d));
563-
Ok(path::windows::Path::new(bytes))
563+
Ok(old_path::windows::Path::new(bytes))
564564
}
565565
}
566566

branches/tmp/src/libstd/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn current_dir() -> IoResult<Path> {
5757
///
5858
/// ```rust
5959
/// use std::env;
60-
/// use std::path::Path;
60+
/// use std::old_path::Path;
6161
///
6262
/// let root = Path::new("/");
6363
/// assert!(env::set_current_dir(&root).is_ok());

0 commit comments

Comments
 (0)