From ac113d340a96c3a1f25783295958990748fc4f65 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Mon, 16 Nov 2020 16:14:53 -0800 Subject: [PATCH] Change some runtime maps to be HashMap instead of BTreeMap This should hypothetically be faster, but we'll see how that plays out. Signed-off-by: Alek Ratzloff --- src/obj/attrs.rs | 4 ++-- src/obj/builtin.rs | 8 ++++---- src/obj/fun.rs | 1 + src/obj/macros.rs | 8 ++++---- src/obj/sym.rs | 4 ++-- src/vm/frame.rs | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/obj/attrs.rs b/src/obj/attrs.rs index f912ed8..ca9af28 100644 --- a/src/obj/attrs.rs +++ b/src/obj/attrs.rs @@ -1,11 +1,11 @@ use crate::obj::{sym::Sym, ObjRef}; use shredder::{Gc, Scan}; use std::{ - collections::BTreeMap, + collections::HashMap, ops::{Deref, DerefMut}, }; -pub type Attrs = BTreeMap; +pub type Attrs = HashMap; pub type VtableAttrs = Gc; #[derive(Scan, Debug, Clone, Default)] diff --git a/src/obj/builtin.rs b/src/obj/builtin.rs index 5a4edc2..129bed5 100644 --- a/src/obj/builtin.rs +++ b/src/obj/builtin.rs @@ -4,9 +4,9 @@ use crate::{ obj::{prelude::*, reserved::*}, vm::{error::*, signal::*}, }; -use maplit::btreemap; +use maplit::hashmap; use once_cell::sync::Lazy; -use std::collections::BTreeMap; +use std::collections::HashMap; //////////////////////////////////////////////////////////////////////////////// // Builtin free functions @@ -74,8 +74,8 @@ pub static PRINT_BUILTIN_FUN: Lazy = Lazy::new(|| { // Builtin objects //////////////////////////////////////////////////////////////////////////////// -pub static BUILTIN_OBJS: Lazy> = Lazy::new(|| { - btreemap! { +pub static BUILTIN_OBJS: Lazy> = Lazy::new(|| { + hashmap! { PRINTLN_BUILTIN_NAME.sym => PRINTLN_BUILTIN_FUN.clone() as _, PRINT_BUILTIN_NAME.sym => PRINT_BUILTIN_FUN.clone() as _, } diff --git a/src/obj/fun.rs b/src/obj/fun.rs index cd3be7a..eeefd51 100644 --- a/src/obj/fun.rs +++ b/src/obj/fun.rs @@ -121,6 +121,7 @@ impl UserFun { &self.locals } + /// Dump this function's code to the given writer. pub fn dump( &self, writer: &mut dyn Write, diff --git a/src/obj/macros.rs b/src/obj/macros.rs index 88177fe..2718d88 100644 --- a/src/obj/macros.rs +++ b/src/obj/macros.rs @@ -86,22 +86,22 @@ macro_rules! read_obj_downcast { #[macro_export] macro_rules! attrs { ($($key:expr => $value:expr),+ $(,)?) => {{ - maplit::btreemap! { $($key => ($value as _) ),+ } + maplit::hashmap! { $($key => ($value as _) ),+ } }}; () => {{ - maplit::btreemap! { } + maplit::hashmap! { } }} } #[macro_export] macro_rules! vtable { ($($key:expr => $value:expr),+ $(,)?) => {{ - $crate::obj::attrs::Vtable::new(maplit::btreemap! { $($key => ($value as _) ),+ }) + $crate::obj::attrs::Vtable::new(maplit::hashmap! { $($key => ($value as _) ),+ }) }}; () => {{ - $crate::obj::attrs::Vtable::new(maplit::btreemap! { }) + $crate::obj::attrs::Vtable::new(maplit::hashmap! { }) }} } diff --git a/src/obj/sym.rs b/src/obj/sym.rs index b5f1855..d79a7bb 100644 --- a/src/obj/sym.rs +++ b/src/obj/sym.rs @@ -1,7 +1,7 @@ use crate::obj::{intern::Interner, prelude::*, reserved::*}; use once_cell::sync::Lazy; use std::{ - collections::BTreeMap, + collections::HashMap, sync::{Arc, Mutex}, }; @@ -69,7 +69,7 @@ pub static SYM_VTABLE: Lazy = Lazy::new(|| vtable! {}); // // global interned symbol obj table // -pub(crate) static SYM_REFS: Lazy>> = Lazy::new(|| Default::default()); +pub(crate) static SYM_REFS: Lazy>> = Lazy::new(|| Default::default()); /// Access or insert a globally interned symbol object. /// diff --git a/src/vm/frame.rs b/src/vm/frame.rs index 4f55b4f..4cc9830 100644 --- a/src/vm/frame.rs +++ b/src/vm/frame.rs @@ -1,8 +1,8 @@ use crate::{obj::prelude::*, vm::inst::Inst}; use std::fmt::{self, Debug, Formatter}; -use std::{collections::BTreeMap, sync::Arc}; +use std::{collections::HashMap, sync::Arc}; -pub type FrameBindings = BTreeMap; +pub type FrameBindings = HashMap; #[derive(Debug)] pub enum Frame {