don't create and drop a new function every call
This commit is contained in:
parent
9a03ac199a
commit
3ad9d45452
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::{hash_map::Entry,HashMap};
|
||||||
|
|
||||||
use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
||||||
use rbx_types::Ref;
|
use rbx_types::Ref;
|
||||||
@ -404,9 +404,12 @@ impl ClassMethods<'_>{
|
|||||||
fn get_or_create_function(&mut self,lua:&mlua::Lua,index:&str)->mlua::Result<Option<mlua::Function>>{
|
fn get_or_create_function(&mut self,lua:&mlua::Lua,index:&str)->mlua::Result<Option<mlua::Function>>{
|
||||||
Ok(match self.method_pointers.get_entry(index){
|
Ok(match self.method_pointers.get_entry(index){
|
||||||
Some((&static_index_str,&function_pointer))=>Some(
|
Some((&static_index_str,&function_pointer))=>Some(
|
||||||
self.methods.entry(static_index_str)
|
match self.methods.entry(static_index_str){
|
||||||
.or_insert(lua.create_function(function_pointer)?)
|
Entry::Occupied(entry)=>entry.get().clone(),
|
||||||
.clone()
|
Entry::Vacant(entry)=>entry.insert(
|
||||||
|
lua.create_function(function_pointer)?
|
||||||
|
).clone(),
|
||||||
|
}
|
||||||
),
|
),
|
||||||
None=>None,
|
None=>None,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user