Skip to content

Commit 55a303e

Browse files
committed
---
yaml --- r: 196605 b: refs/heads/try c: c0dd239 h: refs/heads/master i: 196603: e9f0393 v: v3
1 parent d4b7ca6 commit 55a303e

File tree

28 files changed

+186
-616
lines changed

28 files changed

+186
-616
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b41f2df4ca92e9ab816d9b6649c0fc5df9e9d213
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b3317d68910900f135f9f38e43a7a699bc736b4a
5-
refs/heads/try: 242ed0b7c0f6a21096f2cc3e1ad1bdb176d02545
5+
refs/heads/try: c0dd239753ab22d059531472b3895669ce44a875
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/libcollections/btree/map.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,39 +1143,15 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
11431143
}
11441144

11451145
impl<'a, K: Ord, V> Entry<'a, K, V> {
1146+
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
11461147
#[unstable(feature = "std_misc",
11471148
reason = "will soon be replaced by or_insert")]
1148-
#[deprecated(since = "1.0",
1149-
reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
1150-
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
11511149
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
11521150
match self {
11531151
Occupied(entry) => Ok(entry.into_mut()),
11541152
Vacant(entry) => Err(entry),
11551153
}
11561154
}
1157-
1158-
#[unstable(feature = "collections",
1159-
reason = "matches entry v3 specification, waiting for dust to settle")]
1160-
/// Ensures a value is in the entry by inserting the default if empty, and returns
1161-
/// a mutable reference to the value in the entry.
1162-
pub fn or_insert(self, default: V) -> &'a mut V {
1163-
match self {
1164-
Occupied(entry) => entry.into_mut(),
1165-
Vacant(entry) => entry.insert(default),
1166-
}
1167-
}
1168-
1169-
#[unstable(feature = "collections",
1170-
reason = "matches entry v3 specification, waiting for dust to settle")]
1171-
/// Ensures a value is in the entry by inserting the result of the default function if empty,
1172-
/// and returns a mutable reference to the value in the entry.
1173-
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
1174-
match self {
1175-
Occupied(entry) => entry.into_mut(),
1176-
Vacant(entry) => entry.insert(default()),
1177-
}
1178-
}
11791155
}
11801156

11811157
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
@@ -1587,12 +1563,21 @@ impl<K: Ord, V> BTreeMap<K, V> {
15871563
/// ```
15881564
/// # #![feature(collections)]
15891565
/// use std::collections::BTreeMap;
1566+
/// use std::collections::btree_map::Entry;
15901567
///
15911568
/// let mut count: BTreeMap<&str, usize> = BTreeMap::new();
15921569
///
15931570
/// // count the number of occurrences of letters in the vec
1594-
/// for x in vec!["a","b","a","c","a","b"] {
1595-
/// *count.entry(x).or_insert(0) += 1;
1571+
/// for x in vec!["a","b","a","c","a","b"].iter() {
1572+
/// match count.entry(*x) {
1573+
/// Entry::Vacant(view) => {
1574+
/// view.insert(1);
1575+
/// },
1576+
/// Entry::Occupied(mut view) => {
1577+
/// let v = view.get_mut();
1578+
/// *v += 1;
1579+
/// },
1580+
/// }
15961581
/// }
15971582
///
15981583
/// assert_eq!(count["a"], 3);

branches/try/src/libcollections/vec_map.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,21 @@ impl<V> VecMap<V> {
632632
/// ```
633633
/// # #![feature(collections)]
634634
/// use std::collections::VecMap;
635+
/// use std::collections::vec_map::Entry;
635636
///
636637
/// let mut count: VecMap<u32> = VecMap::new();
637638
///
638639
/// // count the number of occurrences of numbers in the vec
639-
/// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4] {
640-
/// *count.entry(x).or_insert(0) += 1;
640+
/// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4].iter() {
641+
/// match count.entry(*x) {
642+
/// Entry::Vacant(view) => {
643+
/// view.insert(1);
644+
/// },
645+
/// Entry::Occupied(mut view) => {
646+
/// let v = view.get_mut();
647+
/// *v += 1;
648+
/// },
649+
/// }
641650
/// }
642651
///
643652
/// assert_eq!(count[1], 3);
@@ -666,37 +675,13 @@ impl<V> VecMap<V> {
666675
impl<'a, V> Entry<'a, V> {
667676
#[unstable(feature = "collections",
668677
reason = "will soon be replaced by or_insert")]
669-
#[deprecated(since = "1.0",
670-
reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
671678
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
672679
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
673680
match self {
674681
Occupied(entry) => Ok(entry.into_mut()),
675682
Vacant(entry) => Err(entry),
676683
}
677684
}
678-
679-
#[unstable(feature = "collections",
680-
reason = "matches entry v3 specification, waiting for dust to settle")]
681-
/// Ensures a value is in the entry by inserting the default if empty, and returns
682-
/// a mutable reference to the value in the entry.
683-
pub fn or_insert(self, default: V) -> &'a mut V {
684-
match self {
685-
Occupied(entry) => entry.into_mut(),
686-
Vacant(entry) => entry.insert(default),
687-
}
688-
}
689-
690-
#[unstable(feature = "collections",
691-
reason = "matches entry v3 specification, waiting for dust to settle")]
692-
/// Ensures a value is in the entry by inserting the result of the default function if empty,
693-
/// and returns a mutable reference to the value in the entry.
694-
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
695-
match self {
696-
Occupied(entry) => entry.into_mut(),
697-
Vacant(entry) => entry.insert(default()),
698-
}
699-
}
700685
}
701686

702687
impl<'a, V> VacantEntry<'a, V> {

branches/try/src/librustc/metadata/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ impl<'a> Context<'a> {
426426
info!("lib candidate: {}", path.display());
427427

428428
let hash_str = hash.to_string();
429-
let slot = candidates.entry(hash_str)
430-
.or_insert_with(|| (HashMap::new(), HashMap::new()));
429+
let slot = candidates.entry(hash_str).get().unwrap_or_else(
430+
|vacant_entry| vacant_entry.insert((HashMap::new(), HashMap::new())));
431431
let (ref mut rlibs, ref mut dylibs) = *slot;
432432
if rlib {
433433
rlibs.insert(fs::realpath(path).unwrap(), kind);

branches/try/src/librustc/middle/dataflow.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>,
160160

161161
cfg.graph.each_node(|node_idx, node| {
162162
if let cfg::CFGNodeData::AST(id) = node.data {
163-
index.entry(id).or_insert(vec![]).push(node_idx);
163+
match index.entry(id).get() {
164+
Ok(v) => v.push(node_idx),
165+
Err(e) => {
166+
e.insert(vec![node_idx]);
167+
}
168+
}
164169
}
165170
true
166171
});
@@ -180,7 +185,12 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>,
180185
visit::walk_fn_decl(&mut formals, decl);
181186
impl<'a, 'v> visit::Visitor<'v> for Formals<'a> {
182187
fn visit_pat(&mut self, p: &ast::Pat) {
183-
self.index.entry(p.id).or_insert(vec![]).push(self.entry);
188+
match self.index.entry(p.id).get() {
189+
Ok(v) => v.push(self.entry),
190+
Err(e) => {
191+
e.insert(vec![self.entry]);
192+
}
193+
}
184194
visit::walk_pat(self, p)
185195
}
186196
}

branches/try/src/librustc/middle/traits/fulfill.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use middle::infer::{InferCtxt};
1212
use middle::ty::{self, RegionEscape, Ty};
1313
use std::collections::HashSet;
14+
use std::collections::hash_map::Entry::{Occupied, Vacant};
1415
use std::default::Default;
1516
use syntax::ast;
1617
use util::common::ErrorReported;
@@ -436,7 +437,9 @@ fn register_region_obligation<'tcx>(tcx: &ty::ctxt<'tcx>,
436437
debug!("register_region_obligation({})",
437438
region_obligation.repr(tcx));
438439

439-
region_obligations.entry(region_obligation.cause.body_id).or_insert(vec![])
440-
.push(region_obligation);
440+
match region_obligations.entry(region_obligation.cause.body_id) {
441+
Vacant(entry) => { entry.insert(vec![region_obligation]); },
442+
Occupied(mut entry) => { entry.get_mut().push(region_obligation); },
443+
}
441444

442445
}

branches/try/src/librustc/middle/ty.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5669,7 +5669,9 @@ pub fn lookup_field_type<'tcx>(tcx: &ctxt<'tcx>,
56695669
node_id_to_type(tcx, id.node)
56705670
} else {
56715671
let mut tcache = tcx.tcache.borrow_mut();
5672-
tcache.entry(id).or_insert_with(|| csearch::get_field_type(tcx, struct_id, id)).ty
5672+
let pty = tcache.entry(id).get().unwrap_or_else(
5673+
|vacant_entry| vacant_entry.insert(csearch::get_field_type(tcx, struct_id, id)));
5674+
pty.ty
56735675
};
56745676
ty.subst(tcx, substs)
56755677
}
@@ -6817,7 +6819,9 @@ pub fn replace_late_bound_regions<'tcx, T, F>(
68176819
debug!("region={}", region.repr(tcx));
68186820
match region {
68196821
ty::ReLateBound(debruijn, br) if debruijn.depth == current_depth => {
6820-
let region = *map.entry(br).or_insert_with(|| mapf(br));
6822+
let region =
6823+
* map.entry(br).get().unwrap_or_else(
6824+
|vacant_entry| vacant_entry.insert(mapf(br)));
68216825

68226826
if let ty::ReLateBound(debruijn1, br) = region {
68236827
// If the callback returns a late-bound region,

branches/try/src/librustc/session/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use syntax::parse::token::InternedString;
3535

3636
use getopts;
3737
use std::collections::HashMap;
38+
use std::collections::hash_map::Entry::{Occupied, Vacant};
3839
use std::env;
3940
use std::fmt;
4041
use std::path::PathBuf;
@@ -1036,7 +1037,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10361037
None => early_error("--extern value must be of the format `foo=bar`"),
10371038
};
10381039

1039-
externs.entry(name.to_string()).or_insert(vec![]).push(location.to_string());
1040+
match externs.entry(name.to_string()) {
1041+
Vacant(entry) => { entry.insert(vec![location.to_string()]); },
1042+
Occupied(mut entry) => { entry.get_mut().push(location.to_string()); },
1043+
}
10401044
}
10411045

10421046
let crate_name = matches.opt_str("crate-name");

branches/try/src/librustc_resolve/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![feature(rustc_diagnostic_macros)]
2727
#![feature(rustc_private)]
2828
#![feature(staged_api)]
29+
#![feature(std_misc)]
2930

3031
#[macro_use] extern crate log;
3132
#[macro_use] extern crate syntax;

branches/try/src/librustc_resolve/resolve_imports.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
836836
let is_public = import_directive.is_public;
837837

838838
let mut import_resolutions = module_.import_resolutions.borrow_mut();
839-
let dest_import_resolution = import_resolutions.entry(name)
840-
.or_insert_with(|| ImportResolution::new(id, is_public));
839+
let dest_import_resolution = import_resolutions.entry(name).get().unwrap_or_else(
840+
|vacant_entry| {
841+
// Create a new import resolution from this child.
842+
vacant_entry.insert(ImportResolution::new(id, is_public))
843+
});
841844

842845
debug!("(resolving glob import) writing resolution `{}` in `{}` \
843846
to `{}`",

branches/try/src/librustc_typeck/check/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
112112
use util::lev_distance::lev_distance;
113113

114114
use std::cell::{Cell, Ref, RefCell};
115+
use std::collections::hash_map::Entry::{Occupied, Vacant};
115116
use std::mem::replace;
116117
use std::rc::Rc;
117118
use std::iter::repeat;
@@ -1361,7 +1362,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13611362
closure_def_id: ast::DefId,
13621363
r: DeferredCallResolutionHandler<'tcx>) {
13631364
let mut deferred_call_resolutions = self.inh.deferred_call_resolutions.borrow_mut();
1364-
deferred_call_resolutions.entry(closure_def_id).or_insert(vec![]).push(r);
1365+
let mut vec = match deferred_call_resolutions.entry(closure_def_id) {
1366+
Occupied(entry) => entry.into_mut(),
1367+
Vacant(entry) => entry.insert(Vec::new()),
1368+
};
1369+
vec.push(r);
13651370
}
13661371

13671372
fn remove_deferred_call_resolutions(&self,

branches/try/src/librustdoc/html/render.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,9 @@ impl DocFolder for Cache {
876876
if let clean::ImplItem(ref i) = item.inner {
877877
match i.trait_ {
878878
Some(clean::ResolvedPath{ did, .. }) => {
879-
self.implementors.entry(did).or_insert(vec![]).push(Implementor {
879+
let v = self.implementors.entry(did).get().unwrap_or_else(
880+
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
881+
v.push(Implementor {
880882
def_id: item.def_id,
881883
generics: i.generics.clone(),
882884
trait_: i.trait_.as_ref().unwrap().clone(),
@@ -1078,7 +1080,9 @@ impl DocFolder for Cache {
10781080
};
10791081

10801082
if let Some(did) = did {
1081-
self.impls.entry(did).or_insert(vec![]).push(Impl {
1083+
let v = self.impls.entry(did).get().unwrap_or_else(
1084+
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
1085+
v.push(Impl {
10821086
impl_: i,
10831087
dox: dox,
10841088
stability: item.stability.clone(),
@@ -1330,8 +1334,9 @@ impl Context {
13301334
Some(ref s) => s.to_string(),
13311335
};
13321336
let short = short.to_string();
1333-
map.entry(short).or_insert(vec![])
1334-
.push((myname, Some(plain_summary_line(item.doc_value()))));
1337+
let v = map.entry(short).get().unwrap_or_else(
1338+
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
1339+
v.push((myname, Some(plain_summary_line(item.doc_value()))));
13351340
}
13361341

13371342
for (_, items) in &mut map {

branches/try/src/librustdoc/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
352352
}
353353
};
354354
let name = name.to_string();
355-
externs.entry(name).or_insert(vec![]).push(location.to_string());
355+
let locs = externs.entry(name).get().unwrap_or_else(
356+
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
357+
locs.push(location.to_string());
356358
}
357359
Ok(externs)
358360
}

branches/try/src/libstd/collections/hash/map.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hash::{Hash, SipHasher};
2323
use iter::{self, Iterator, ExactSizeIterator, IntoIterator, IteratorExt, FromIterator, Extend, Map};
2424
use marker::Sized;
2525
use mem::{self, replace};
26-
use ops::{Deref, FnMut, FnOnce, Index};
26+
use ops::{Deref, FnMut, Index};
2727
use option::Option::{self, Some, None};
2828
use rand::{self, Rng};
2929
use result::Result::{self, Ok, Err};
@@ -1488,37 +1488,12 @@ impl<'a, K, V> Entry<'a, K, V> {
14881488
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant.
14891489
#[unstable(feature = "std_misc",
14901490
reason = "will soon be replaced by or_insert")]
1491-
#[deprecated(since = "1.0",
1492-
reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
1493-
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
14941491
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
14951492
match self {
14961493
Occupied(entry) => Ok(entry.into_mut()),
14971494
Vacant(entry) => Err(entry),
14981495
}
14991496
}
1500-
1501-
#[unstable(feature = "collections",
1502-
reason = "matches entry v3 specification, waiting for dust to settle")]
1503-
/// Ensures a value is in the entry by inserting the default if empty, and returns
1504-
/// a mutable reference to the value in the entry.
1505-
pub fn or_insert(self, default: V) -> &'a mut V {
1506-
match self {
1507-
Occupied(entry) => entry.into_mut(),
1508-
Vacant(entry) => entry.insert(default),
1509-
}
1510-
}
1511-
1512-
#[unstable(feature = "collections",
1513-
reason = "matches entry v3 specification, waiting for dust to settle")]
1514-
/// Ensures a value is in the entry by inserting the result of the default function if empty,
1515-
/// and returns a mutable reference to the value in the entry.
1516-
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
1517-
match self {
1518-
Occupied(entry) => entry.into_mut(),
1519-
Vacant(entry) => entry.insert(default()),
1520-
}
1521-
}
15221497
}
15231498

15241499
impl<'a, K, V> OccupiedEntry<'a, K, V> {

branches/try/src/libstd/collections/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@
307307
//! let message = "she sells sea shells by the sea shore";
308308
//!
309309
//! for c in message.chars() {
310-
//! *count.entry(c).or_insert(0) += 1;
310+
//! match count.entry(c) {
311+
//! Entry::Vacant(entry) => { entry.insert(1); },
312+
//! Entry::Occupied(mut entry) => *entry.get_mut() += 1,
313+
//! }
311314
//! }
312315
//!
313316
//! assert_eq!(count.get(&'s'), Some(&8));
@@ -340,7 +343,10 @@
340343
//! for id in orders.into_iter() {
341344
//! // If this is the first time we've seen this customer, initialize them
342345
//! // with no blood alcohol. Otherwise, just retrieve them.
343-
//! let person = blood_alcohol.entry(id).or_insert(Person{id: id, blood_alcohol: 0.0});
346+
//! let person = match blood_alcohol.entry(id) {
347+
//! Entry::Vacant(entry) => entry.insert(Person{id: id, blood_alcohol: 0.0}),
348+
//! Entry::Occupied(entry) => entry.into_mut(),
349+
//! };
344350
//!
345351
//! // Reduce their blood alcohol level. It takes time to order and drink a beer!
346352
//! person.blood_alcohol *= 0.9;

0 commit comments

Comments
 (0)