aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/buffer_map.rs
diff options
context:
space:
mode:
authorJack Moffitt <jack@metajack.im>2014-11-05 12:33:11 -0700
committerGlenn Watson <gw@intuitionlibrary.com>2014-11-13 11:17:43 +1000
commitd1b433a3b3bab353f320b2f39fa953ce326d2d55 (patch)
treed7a197abb65827b36c47e6b5c3adcce9071643d3 /components/gfx/buffer_map.rs
parent26045d7fcbab8851fbefe2851cd904203f8fd8dd (diff)
downloadservo-d1b433a3b3bab353f320b2f39fa953ce326d2d55.tar.gz
servo-d1b433a3b3bab353f320b2f39fa953ce326d2d55.zip
Rust upgrade to rustc hash b03a2755193cd756583bcf5831cf4545d75ecb8a
Diffstat (limited to 'components/gfx/buffer_map.rs')
-rw-r--r--components/gfx/buffer_map.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/components/gfx/buffer_map.rs b/components/gfx/buffer_map.rs
index 79612f6a9bd..04dc2a28f19 100644
--- a/components/gfx/buffer_map.rs
+++ b/components/gfx/buffer_map.rs
@@ -2,7 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use std::collections::hashmap::HashMap;
+use std::collections::HashMap;
+use std::collections::hash_map::{Occupied, Vacant};
use geom::size::Size2D;
use layers::platform::surface::NativePaintingGraphicsContext;
use layers::layers::LayerBuffer;
@@ -85,10 +86,17 @@ impl BufferMap {
self.mem += new_buffer.get_mem();
// use lazy insertion function to prevent unnecessary allocation
let counter = &self.counter;
- self.map.find_or_insert_with(new_key, |_| BufferValue {
- buffers: vec!(),
- last_action: *counter
- }).buffers.push(new_buffer);
+ match self.map.entry(new_key) {
+ Occupied(entry) => {
+ entry.into_mut().buffers.push(new_buffer);
+ }
+ Vacant(entry) => {
+ entry.set(BufferValue {
+ buffers: vec!(new_buffer),
+ last_action: *counter,
+ });
+ }
+ }
let mut opt_key: Option<BufferKey> = None;
while self.mem > self.max_mem {
@@ -97,19 +105,19 @@ impl BufferMap {
None => {
match self.map.iter().min_by(|&(_, x)| x.last_action) {
Some((k, _)) => *k,
- None => fail!("BufferMap: tried to delete with no elements in map"),
+ None => panic!("BufferMap: tried to delete with no elements in map"),
}
}
};
if {
- let list = &mut self.map.get_mut(&old_key).buffers;
+ let list = &mut self.map[old_key].buffers;
let condemned_buffer = list.pop().take().unwrap();
self.mem -= condemned_buffer.get_mem();
condemned_buffer.destroy(graphics_context);
list.is_empty()
}
{ // then
- self.map.pop(&old_key); // Don't store empty vectors!
+ self.map.remove(&old_key); // Don't store empty vectors!
opt_key = None;
} else {
opt_key = Some(old_key);
@@ -121,7 +129,7 @@ impl BufferMap {
pub fn find(&mut self, size: Size2D<uint>) -> Option<Box<LayerBuffer>> {
let mut flag = false; // True if key needs to be popped after retrieval.
let key = BufferKey::get(size);
- let ret = match self.map.find_mut(&key) {
+ let ret = match self.map.get_mut(&key) {
Some(ref mut buffer_val) => {
buffer_val.last_action = self.counter;
self.counter += 1;
@@ -137,7 +145,7 @@ impl BufferMap {
};
if flag {
- self.map.pop(&key); // Don't store empty vectors!
+ self.map.remove(&key); // Don't store empty vectors!
}
ret