Skip to content

Commit 5e95013

Browse files
committed
Use directly integers instead of ObjectRef as index of ObjectStore's HashMap.
1 parent e064aa4 commit 5e95013

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/objects/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ impl ObjectRef {
216216

217217

218218
pub struct ObjectStore {
219-
all_objects: HashMap<ObjectRef, Object>,
219+
all_objects: HashMap<usize, Object>,
220220
}
221221

222222
impl fmt::Debug for ObjectStore {
223223
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
224224
try!(write!(f, "ObjectStore {{ all_objects: HashMap {{\n"));
225-
for (ref obj_ref, ref obj) in self.all_objects.iter() {
226-
try!(write!(f, "\t{} => {:?}\n", obj_ref.id, obj));
225+
for (ref id, ref obj) in self.all_objects.iter() {
226+
try!(write!(f, "\t{} => {:?}\n", id, obj));
227227
}
228228
write!(f, "}}}}\n")
229229
}
@@ -236,24 +236,24 @@ impl ObjectStore {
236236

237237
pub fn allocate(&mut self, obj: Object) -> ObjectRef {
238238
let obj_ref = ObjectRef::new();
239-
self.all_objects.insert(obj_ref.clone(), obj);
239+
self.all_objects.insert(obj_ref.id.clone(), obj);
240240
obj_ref
241241
}
242242

243243
pub fn allocate_at(&mut self, obj_ref: ObjectRef, obj: Object) {
244-
match self.all_objects.get(&obj_ref) {
245-
None => self.all_objects.insert(obj_ref, obj),
244+
match self.all_objects.get(&obj_ref.id) {
245+
None => self.all_objects.insert(obj_ref.id, obj),
246246
_ => panic!("Already allocated"),
247247
};
248248
}
249249

250250
pub fn deref(&self, obj_ref: &ObjectRef) -> &Object {
251251
// TODO: check the reference is valid
252-
self.all_objects.get(obj_ref).unwrap()
252+
self.all_objects.get(&obj_ref.id).unwrap()
253253
}
254254
pub fn deref_mut(&mut self, obj_ref: &ObjectRef) -> &mut Object {
255255
// TODO: check the reference is valid
256-
self.all_objects.get_mut(obj_ref).unwrap()
256+
self.all_objects.get_mut(&obj_ref.id).unwrap()
257257
}
258258
}
259259

0 commit comments

Comments
 (0)