From fbe4b56c628a795e3a795ba2842f1210639cbcd8 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 5 Oct 2024 15:12:03 -0700 Subject: [PATCH] try using &'static str from function database instead of provided index str --- src/runner/instance.rs | 54 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 7ea4079..c336cba 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{hash_map::Entry,HashMap}; use mlua::{IntoLua,IntoLuaMulti}; use rbx_types::Ref; @@ -264,39 +264,37 @@ impl mlua::UserData for Instance{ //find a function with a matching name if let Some(ret)=class_functions_mut(lua,|cf|{ let class_str=instance.class.as_str(); - Ok(match cf.classes.entry(class_str){ - std::collections::hash_map::Entry::Occupied(occupied_entry)=>{ - match occupied_entry.get().entry(index_str){ - std::collections::hash_map::Entry::Occupied(occupied_entry)=>{ - Some(occupied_entry.get()) + Ok(match CLASS_FUNCTION_DATABASE.get_entry(class_str){ + Some((&static_class_str,class_functions))=>{ + match cf.classes.entry(static_class_str){ + Entry::Occupied(occupied_entry)=>{ + match class_functions.get_entry(index_str){ + Some((&static_index_str,function_pointer))=>{ + match occupied_entry.get().entry(static_index_str){ + Entry::Occupied(occupied_entry)=>{ + Some(*occupied_entry.get()) + }, + Entry::Vacant(vacant_entry)=>{ + Some(*vacant_entry.insert(lua.create_function(function_pointer)?)) + }, + } + }, + None=>None, + } }, - std::collections::hash_map::Entry::Vacant(vacant_entry)=>{ - match CLASS_FUNCTION_DATABASE.get(class_str) - .and_then(|class_functions| - class_functions.get(index_str) - ) - { - Some(f_pointer)=>Some(&*vacant_entry.insert(lua.create_function(f_pointer)?)), + Entry::Vacant(vacant_entry)=>{ + match class_functions.get_entry(index_str){ + Some((&static_index_str,function_pointer))=>{ + let mut h=HashMap::new(); + h.entry(static_index_str).or_insert(lua.create_function(function_pointer)?); + vacant_entry.insert(h).get(static_index_str).map(|f|*f) + }, None=>None, } }, } }, - std::collections::hash_map::Entry::Vacant(vacant_entry)=>{ - match CLASS_FUNCTION_DATABASE.get(class_str) - .and_then(|class_functions| - class_functions.get(index_str) - ) - { - Some(f_pointer)=>{ - let mut h=HashMap::new(); - let lua_f=h.entry(index_str).or_insert(lua.create_function(f_pointer)?); - vacant_entry.insert(h); - Some(&*lua_f) - }, - None=>None, - } - }, + None=>None, }) })?{ return Ok(ret.into_lua(lua));