Skip to content

Commit 66f9237

Browse files
author
Jakub Bukaj
committed
---
yaml --- r: 159710 b: refs/heads/auto c: 7783e80 h: refs/heads/master v: v3
1 parent de7d0a7 commit 66f9237

File tree

53 files changed

+592
-299
lines changed

Some content is hidden

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

53 files changed

+592
-299
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 54c76e6e8193e96b2ca15542f916a7520cfaa75f
13+
refs/heads/auto: 7783e80d9894272d521fe019fbd4d0eb69bf8d7d
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/grammar/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
178178
let toknum = m.name("toknum");
179179
let content = m.name("content");
180180

181-
let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map",
181+
let proto_tok = tokens.get(&toknum).expect(format!("didn't find token {} in the map",
182182
toknum).as_slice());
183183

184184
let nm = parse::token::intern(content);

branches/auto/src/libcollections/bit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Bitv {
283283
x != 0
284284
}
285285

286-
/// Sets the value of a bit at a index `i`.
286+
/// Sets the value of a bit at an index `i`.
287287
///
288288
/// # Panics
289289
///
@@ -582,7 +582,7 @@ impl Bitv {
582582
///
583583
/// # Panics
584584
///
585-
/// Panics if the the `Bitv` and slice are of different length.
585+
/// Panics if the `Bitv` and slice are of different length.
586586
///
587587
/// # Example
588588
///

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use core::prelude::*;
2121

2222
use self::StackOp::*;
2323
use super::node::*;
24+
use core::borrow::BorrowFrom;
2425
use std::hash::{Writer, Hash};
2526
use core::default::Default;
2627
use core::{iter, fmt, mem};
@@ -56,7 +57,7 @@ use ring_buf::RingBuf;
5657
/// and possibly other factors. Using linear search, searching for a random element is expected
5758
/// to take O(B log<sub>B</sub>n) comparisons, which is generally worse than a BST. In practice,
5859
/// however, performance is excellent. `BTreeMap` is able to readily outperform `TreeMap` under
59-
/// many workloads, and is competetive where it doesn't. BTreeMap also generally *scales* better
60+
/// many workloads, and is competitive where it doesn't. BTreeMap also generally *scales* better
6061
/// than TreeMap, making it more appropriate for large datasets.
6162
///
6263
/// However, `TreeMap` may still be more appropriate to use in many contexts. If elements are very
@@ -184,6 +185,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
184185

185186
/// Returns a reference to the value corresponding to the key.
186187
///
188+
/// The key may be any borrowed form of the map's key type, but the ordering
189+
/// on the borrowed form *must* match the ordering on the key type.
190+
///
187191
/// # Example
188192
///
189193
/// ```
@@ -195,7 +199,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
195199
/// assert_eq!(map.get(&2), None);
196200
/// ```
197201
#[unstable = "matches collection reform specification, waiting for dust to settle"]
198-
pub fn get(&self, key: &K) -> Option<&V> {
202+
pub fn get<Sized? Q>(&self, key: &Q) -> Option<&V> where Q: BorrowFrom<K> + Ord {
199203
let mut cur_node = &self.root;
200204
loop {
201205
match cur_node.search(key) {
@@ -213,6 +217,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
213217

214218
/// Returns true if the map contains a value for the specified key.
215219
///
220+
/// The key may be any borrowed form of the map's key type, but the ordering
221+
/// on the borrowed form *must* match the ordering on the key type.
222+
///
216223
/// # Example
217224
///
218225
/// ```
@@ -224,7 +231,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
224231
/// assert_eq!(map.contains_key(&2), false);
225232
/// ```
226233
#[unstable = "matches collection reform specification, waiting for dust to settle"]
227-
pub fn contains_key(&self, key: &K) -> bool {
234+
pub fn contains_key<Sized? Q>(&self, key: &Q) -> bool where Q: BorrowFrom<K> + Ord {
228235
self.get(key).is_some()
229236
}
230237

@@ -236,6 +243,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
236243

237244
/// Returns a mutable reference to the value corresponding to the key.
238245
///
246+
/// The key may be any borrowed form of the map's key type, but the ordering
247+
/// on the borrowed form *must* match the ordering on the key type.
248+
///
239249
/// # Example
240250
///
241251
/// ```
@@ -251,7 +261,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
251261
/// ```
252262
// See `get` for implementation notes, this is basically a copy-paste with mut's added
253263
#[unstable = "matches collection reform specification, waiting for dust to settle"]
254-
pub fn get_mut(&mut self, key: &K) -> Option<&mut V> {
264+
pub fn get_mut<Sized? Q>(&mut self, key: &Q) -> Option<&mut V> where Q: BorrowFrom<K> + Ord {
255265
// temp_node is a Borrowck hack for having a mutable value outlive a loop iteration
256266
let mut temp_node = &mut self.root;
257267
loop {
@@ -410,6 +420,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
410420
/// Removes a key from the map, returning the value at the key if the key
411421
/// was previously in the map.
412422
///
423+
/// The key may be any borrowed form of the map's key type, but the ordering
424+
/// on the borrowed form *must* match the ordering on the key type.
425+
///
413426
/// # Example
414427
///
415428
/// ```
@@ -421,7 +434,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
421434
/// assert_eq!(map.remove(&1), None);
422435
/// ```
423436
#[unstable = "matches collection reform specification, waiting for dust to settle"]
424-
pub fn remove(&mut self, key: &K) -> Option<V> {
437+
pub fn remove<Sized? Q>(&mut self, key: &Q) -> Option<V> where Q: BorrowFrom<K> + Ord {
425438
// See `swap` for a more thorough description of the stuff going on in here
426439
let mut stack = stack::PartialSearchStack::new(self);
427440
loop {
@@ -790,14 +803,18 @@ impl<K: Show, V: Show> Show for BTreeMap<K, V> {
790803
}
791804
}
792805

793-
impl<K: Ord, V> Index<K, V> for BTreeMap<K, V> {
794-
fn index(&self, key: &K) -> &V {
806+
impl<K: Ord, Sized? Q, V> Index<Q, V> for BTreeMap<K, V>
807+
where Q: BorrowFrom<K> + Ord
808+
{
809+
fn index(&self, key: &Q) -> &V {
795810
self.get(key).expect("no entry found for key")
796811
}
797812
}
798813

799-
impl<K: Ord, V> IndexMut<K, V> for BTreeMap<K, V> {
800-
fn index_mut(&mut self, key: &K) -> &mut V {
814+
impl<K: Ord, Sized? Q, V> IndexMut<Q, V> for BTreeMap<K, V>
815+
where Q: BorrowFrom<K> + Ord
816+
{
817+
fn index_mut(&mut self, key: &Q) -> &mut V {
801818
self.get_mut(key).expect("no entry found for key")
802819
}
803820
}

branches/auto/src/libcollections/btree/node.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use core::prelude::*;
1919

2020
use core::{slice, mem, ptr};
2121
use core::iter::Zip;
22+
use core::borrow::BorrowFrom;
2223

2324
use vec;
2425
use vec::Vec;
@@ -47,7 +48,7 @@ pub struct Node<K, V> {
4748
// theory, if we take full control of allocation like HashMap's RawTable does,
4849
// and restrict leaves to max size 256 (not unreasonable for a btree node) we can cut
4950
// this down to just (ptr, cap: u8, size: u8, is_leaf: bool). With generic
50-
// integer arguments, cap can even move into the the type, reducing this just to
51+
// integer arguments, cap can even move into the type, reducing this just to
5152
// (ptr, size, is_leaf). This could also have cache benefits for very small nodes, as keys
5253
// could bleed into edges and vals.
5354
//
@@ -73,19 +74,19 @@ impl<K: Ord, V> Node<K, V> {
7374
/// Searches for the given key in the node. If it finds an exact match,
7475
/// `Found` will be yielded with the matching index. If it doesn't find an exact match,
7576
/// `GoDown` will be yielded with the index of the subtree the key must lie in.
76-
pub fn search(&self, key: &K) -> SearchResult {
77+
pub fn search<Sized? Q>(&self, key: &Q) -> SearchResult where Q: BorrowFrom<K> + Ord {
7778
// FIXME(Gankro): Tune when to search linear or binary based on B (and maybe K/V).
7879
// For the B configured as of this writing (B = 6), binary search was *significantly*
7980
// worse for uints.
8081
self.search_linear(key)
8182
}
8283

83-
fn search_linear(&self, key: &K) -> SearchResult {
84+
fn search_linear<Sized? Q>(&self, key: &Q) -> SearchResult where Q: BorrowFrom<K> + Ord {
8485
for (i, k) in self.keys.iter().enumerate() {
85-
match k.cmp(key) {
86-
Less => {},
86+
match key.cmp(BorrowFrom::borrow_from(k)) {
87+
Greater => {},
8788
Equal => return Found(i),
88-
Greater => return GoDown(i),
89+
Less => return GoDown(i),
8990
}
9091
}
9192
GoDown(self.len())

branches/auto/src/libcollections/btree/set.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use core::prelude::*;
1515

1616
use btree_map::{BTreeMap, Keys, MoveEntries};
1717
use std::hash::Hash;
18+
use core::borrow::BorrowFrom;
1819
use core::default::Default;
1920
use core::{iter, fmt};
2021
use core::iter::Peekable;
@@ -167,6 +168,10 @@ impl<T: Ord> BTreeSet<T> {
167168

168169
/// Returns `true` if the set contains a value.
169170
///
171+
/// The value may be any borrowed form of the set's value type,
172+
/// but the ordering on the borrowed form *must* match the
173+
/// ordering on the value type.
174+
///
170175
/// # Example
171176
///
172177
/// ```
@@ -177,7 +182,7 @@ impl<T: Ord> BTreeSet<T> {
177182
/// assert_eq!(set.contains(&4), false);
178183
/// ```
179184
#[unstable = "matches collection reform specification, waiting for dust to settle"]
180-
pub fn contains(&self, value: &T) -> bool {
185+
pub fn contains<Sized? Q>(&self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord {
181186
self.map.contains_key(value)
182187
}
183188

@@ -291,6 +296,10 @@ impl<T: Ord> BTreeSet<T> {
291296
/// Removes a value from the set. Returns `true` if the value was
292297
/// present in the set.
293298
///
299+
/// The value may be any borrowed form of the set's value type,
300+
/// but the ordering on the borrowed form *must* match the
301+
/// ordering on the value type.
302+
///
294303
/// # Example
295304
///
296305
/// ```
@@ -303,7 +312,7 @@ impl<T: Ord> BTreeSet<T> {
303312
/// assert_eq!(set.remove(&2), false);
304313
/// ```
305314
#[unstable = "matches collection reform specification, waiting for dust to settle"]
306-
pub fn remove(&mut self, value: &T) -> bool {
315+
pub fn remove<Sized? Q>(&mut self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord {
307316
self.map.remove(value).is_some()
308317
}
309318
}

branches/auto/src/libcollections/slice.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
use self::Direction::*;
9191
use alloc::boxed::Box;
92+
use core::borrow::{BorrowFrom, BorrowFromMut};
9293
use core::cmp;
9394
use core::kinds::Sized;
9495
use core::mem::size_of;
@@ -647,6 +648,16 @@ impl<T> SliceAllocPrelude<T> for [T] {
647648
}
648649
}
649650

651+
#[unstable = "trait is unstable"]
652+
impl<T> BorrowFrom<Vec<T>> for [T] {
653+
fn borrow_from(owned: &Vec<T>) -> &[T] { owned[] }
654+
}
655+
656+
#[unstable = "trait is unstable"]
657+
impl<T> BorrowFromMut<Vec<T>> for [T] {
658+
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { owned[mut] }
659+
}
660+
650661
/// Unsafe operations
651662
pub mod raw {
652663
pub use core::slice::raw::{buf_as_slice, mut_buf_as_slice};

branches/auto/src/libcollections/str.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
pub use self::MaybeOwned::*;
5555
use self::RecompositionState::*;
5656
use self::DecompositionType::*;
57-
57+
use core::borrow::BorrowFrom;
5858
use core::default::Default;
5959
use core::fmt;
6060
use core::cmp;
@@ -604,6 +604,11 @@ impl<'a> fmt::Show for MaybeOwned<'a> {
604604
}
605605
}
606606

607+
#[unstable = "trait is unstable"]
608+
impl BorrowFrom<String> for str {
609+
fn borrow_from(owned: &String) -> &str { owned[] }
610+
}
611+
607612
/// Unsafe string operations.
608613
pub mod raw {
609614
pub use core::str::raw::{from_utf8, c_str_to_static_slice, slice_bytes};
@@ -1258,13 +1263,13 @@ mod tests {
12581263
#[test]
12591264
fn test_slice_shift_char() {
12601265
let data = "ประเทศไทย中";
1261-
assert_eq!(data.slice_shift_char(), (Some('ป'), "ระเทศไทย中"));
1266+
assert_eq!(data.slice_shift_char(), Some(('ป', "ระเทศไทย中")));
12621267
}
12631268

12641269
#[test]
12651270
fn test_slice_shift_char_2() {
12661271
let empty = "";
1267-
assert_eq!(empty.slice_shift_char(), (None, ""));
1272+
assert_eq!(empty.slice_shift_char(), None);
12681273
}
12691274

12701275
#[test]

branches/auto/src/libcollections/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl String {
549549
///
550550
/// # Warning
551551
///
552-
/// This is a O(n) operation as it requires copying every element in the
552+
/// This is an O(n) operation as it requires copying every element in the
553553
/// buffer.
554554
///
555555
/// # Panics
@@ -586,7 +586,7 @@ impl String {
586586
///
587587
/// # Warning
588588
///
589-
/// This is a O(n) operation as it requires copying every element in the
589+
/// This is an O(n) operation as it requires copying every element in the
590590
/// buffer.
591591
///
592592
/// # Panics

0 commit comments

Comments
 (0)