From 36aa827e15062889e1f3be80deb280bd1b49dbdd Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 23 Nov 2020 21:12:57 +0800 Subject: [PATCH] Simply interned strings dict. --- src/packages/fn_basic.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index 3886c333..9402413c 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -52,7 +52,7 @@ mod fn_ptr_functions { fn collect_fn_metadata(ctx: NativeCallContext) -> Array { // Create a metadata record for a function. fn make_metadata( - dict: &HashMap, + dict: &HashMap<&str, ImmutableString>, namespace: Option, f: SharedScriptFnDef, ) -> Map { @@ -90,7 +90,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> Array { // Recursively scan modules for script-defined functions. fn scan_module( list: &mut Array, - dict: &HashMap, + dict: &HashMap<&str, ImmutableString>, namespace: ImmutableString, module: &Module, ) { @@ -104,14 +104,20 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> Array { } // Intern strings - let mut dict = HashMap::::with_capacity(8); - dict.insert("namespace".into(), "namespace".into()); - dict.insert("name".into(), "name".into()); - dict.insert("access".into(), "access".into()); - dict.insert("public".into(), "public".into()); - dict.insert("private".into(), "private".into()); - dict.insert("is_anonymous".into(), "is_anonymous".into()); - dict.insert("params".into(), "params".into()); + let mut dict = HashMap::<&str, ImmutableString>::with_capacity(8); + [ + "namespace", + "name", + "access", + "public", + "private", + "is_anonymous", + "params", + ] + .iter() + .for_each(|&s| { + dict.insert(s, s.into()); + }); let mut list: Array = Default::default();