Skip to content

Commit 8d10abc

Browse files
committed
glib/subclass/types: use BTreeMap instead of HashMap
According to callgrind using ts-standalone with -s 1000 -n 1000, there's a 17% reduction in estimated cycles for `ElementImplExt::panicked` (invoked more than 1M times) compared to current version which uses `HashMap` with `rustc_hash`. See also: gtk-rs#755
1 parent 9fe7e5c commit 8d10abc

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

glib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ ffi = { package = "glib-sys", path = "sys" }
3131
gobject_ffi = { package = "gobject-sys", path = "gobject-sys" }
3232
glib-macros = { path = "../glib-macros" }
3333
rs-log = { package = "log", version = "0.4", optional = true }
34-
rustc-hash = "1.1.0"
3534
smallvec = "1.0"
3635
thiserror = "1"
3736

glib/src/subclass/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use crate::object::{Cast, IsClass, IsInterface, ObjectSubclassIs, ObjectType, ParentClassIs};
77
use crate::translate::*;
88
use crate::{Closure, Object, StaticType, Type, Value};
9-
use rustc_hash::FxHashMap as HashMap;
109
use std::any::Any;
10+
use std::collections::BTreeMap;
1111
use std::marker;
1212
use std::mem;
1313
use std::ptr;
@@ -33,7 +33,7 @@ impl<T> IntoGlib for InitializingType<T> {
3333
/// Struct used for the instance private data of the GObject.
3434
struct PrivateStruct<T: ObjectSubclass> {
3535
imp: T,
36-
instance_data: Option<HashMap<Type, Box<dyn Any + Send + Sync>>>,
36+
instance_data: Option<BTreeMap<Type, Box<dyn Any + Send + Sync>>>,
3737
}
3838

3939
// rustdoc-stripper-ignore-next
@@ -245,7 +245,7 @@ unsafe extern "C" fn interface_init<T: ObjectSubclass, A: IsImplementable<T>>(
245245

246246
let mut data = T::type_data();
247247
if data.as_ref().parent_ifaces.is_none() {
248-
data.as_mut().parent_ifaces = Some(HashMap::default());
248+
data.as_mut().parent_ifaces = Some(BTreeMap::default());
249249
}
250250
{
251251
let copy = Box::new(*iface.as_ref());
@@ -360,9 +360,9 @@ pub struct TypeData {
360360
#[doc(hidden)]
361361
pub parent_class: ffi::gpointer,
362362
#[doc(hidden)]
363-
pub parent_ifaces: Option<HashMap<Type, ffi::gpointer>>,
363+
pub parent_ifaces: Option<BTreeMap<Type, ffi::gpointer>>,
364364
#[doc(hidden)]
365-
pub class_data: Option<HashMap<Type, Box<dyn Any + Send + Sync>>>,
365+
pub class_data: Option<BTreeMap<Type, Box<dyn Any + Send + Sync>>>,
366366
#[doc(hidden)]
367367
pub private_offset: isize,
368368
#[doc(hidden)]
@@ -452,7 +452,7 @@ impl TypeData {
452452
/// If the class_data already contains a data for the specified `type_`.
453453
pub unsafe fn set_class_data<T: Any + Send + Sync + 'static>(&mut self, type_: Type, data: T) {
454454
if self.class_data.is_none() {
455-
self.class_data = Some(HashMap::default());
455+
self.class_data = Some(BTreeMap::default());
456456
}
457457

458458
if let Some(ref mut class_data) = self.class_data {
@@ -763,7 +763,7 @@ impl<T: ObjectSubclass> InitializingObject<T> {
763763
let priv_ = &mut *ptr;
764764

765765
if priv_.instance_data.is_none() {
766-
priv_.instance_data = Some(HashMap::default());
766+
priv_.instance_data = Some(BTreeMap::default());
767767
}
768768

769769
if let Some(ref mut instance_data) = priv_.instance_data {

0 commit comments

Comments
 (0)