From 3ad9d45452f3e9cba68da23dca502ce8beb737bc Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sun, 6 Oct 2024 16:00:14 -0700 Subject: [PATCH] don't create and drop a new function every call --- src/runner/instance.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index d2b5d8e..8ce90b8 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::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti}; use rbx_types::Ref; @@ -404,9 +404,12 @@ impl ClassMethods<'_>{ fn get_or_create_function(&mut self,lua:&mlua::Lua,index:&str)->mlua::Result>{ Ok(match self.method_pointers.get_entry(index){ Some((&static_index_str,&function_pointer))=>Some( - self.methods.entry(static_index_str) - .or_insert(lua.create_function(function_pointer)?) - .clone() + match self.methods.entry(static_index_str){ + Entry::Occupied(entry)=>entry.get().clone(), + Entry::Vacant(entry)=>entry.insert( + lua.create_function(function_pointer)? + ).clone(), + } ), None=>None, })