collections: Enable IndexMut for some collections
This commit enables implementations of IndexMut for a number of collections, including Vec, RingBuf, SmallIntMap, TrieMap, TreeMap, and HashMap. At the same time this deprecates the `get_mut` methods on vectors in favor of using the indexing notation. cc #18424
This commit is contained in:
@@ -157,7 +157,7 @@ impl<'r> Compiler<'r> {
|
||||
if cap >= len {
|
||||
self.names.grow(10 + cap - len, None)
|
||||
}
|
||||
*self.names.get_mut(cap) = name;
|
||||
self.names[cap] = name;
|
||||
|
||||
self.push(Save(2 * cap));
|
||||
self.compile(*x);
|
||||
@@ -243,7 +243,7 @@ impl<'r> Compiler<'r> {
|
||||
/// `panic!` is called.
|
||||
#[inline]
|
||||
fn set_split(&mut self, i: InstIdx, pc1: InstIdx, pc2: InstIdx) {
|
||||
let split = self.insts.get_mut(i);
|
||||
let split = &mut self.insts[i];
|
||||
match *split {
|
||||
Split(_, _) => *split = Split(pc1, pc2),
|
||||
_ => panic!("BUG: Invalid split index."),
|
||||
@@ -263,7 +263,7 @@ impl<'r> Compiler<'r> {
|
||||
/// `panic!` is called.
|
||||
#[inline]
|
||||
fn set_jump(&mut self, i: InstIdx, pc: InstIdx) {
|
||||
let jmp = self.insts.get_mut(i);
|
||||
let jmp = &mut self.insts[i];
|
||||
match *jmp {
|
||||
Jump(_) => *jmp = Jump(pc),
|
||||
_ => panic!("BUG: Invalid jump index."),
|
||||
|
||||
@@ -978,7 +978,7 @@ fn combine_ranges(unordered: Vec<(char, char)>) -> Vec<(char, char)> {
|
||||
}
|
||||
match which {
|
||||
None => ordered.push((us, ue)),
|
||||
Some(i) => *ordered.get_mut(i) = (us, ue),
|
||||
Some(i) => ordered[i] = (us, ue),
|
||||
}
|
||||
}
|
||||
ordered.sort();
|
||||
|
||||
@@ -461,13 +461,13 @@ impl Threads {
|
||||
}
|
||||
|
||||
fn add(&mut self, pc: uint, groups: &[Option<uint>], empty: bool) {
|
||||
let t = self.queue.get_mut(self.size);
|
||||
let t = &mut self.queue[self.size];
|
||||
t.pc = pc;
|
||||
match (empty, self.which) {
|
||||
(_, Exists) | (true, _) => {},
|
||||
(false, Location) => {
|
||||
*t.groups.get_mut(0) = groups[0];
|
||||
*t.groups.get_mut(1) = groups[1];
|
||||
t.groups[0] = groups[0];
|
||||
t.groups[1] = groups[1];
|
||||
}
|
||||
(false, Submatches) => {
|
||||
for (slot, val) in t.groups.iter_mut().zip(groups.iter()) {
|
||||
@@ -475,7 +475,7 @@ impl Threads {
|
||||
}
|
||||
}
|
||||
}
|
||||
*self.sparse.get_mut(pc) = self.size;
|
||||
self.sparse[pc] = self.size;
|
||||
self.size += 1;
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ impl Threads {
|
||||
|
||||
#[inline]
|
||||
fn groups<'r>(&'r mut self, i: uint) -> &'r mut [Option<uint>] {
|
||||
self.queue.get_mut(i).groups.as_mut_slice()
|
||||
self.queue[i].groups.as_mut_slice()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user