summaryrefslogtreecommitdiff
path: root/src/function.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2021-11-12 10:55:20 +0000
committerAlex Orlenko <zxteam@protonmail.com>2021-11-12 10:55:20 +0000
commit2c7d7117d23e2ca318e42097d6ab5ea699a0a664 (patch)
treee87958e02b35c7994609eefa8f1ee9b9c342b64f /src/function.rs
parent6d689c35aac83dfa94125ae18d7d1badbd6c614e (diff)
downloadmlua-2c7d7117d23e2ca318e42097d6ab5ea699a0a664.zip
Optimize MultiValue allocations (recycle old container)
Diffstat (limited to 'src/function.rs')
-rw-r--r--src/function.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/function.rs b/src/function.rs
index f87d52c..cbb1415 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -6,7 +6,7 @@ use crate::error::{Error, Result};
use crate::ffi;
use crate::types::LuaRef;
use crate::util::{assert_stack, check_stack, error_traceback, pop_error, StackGuard};
-use crate::value::{FromLuaMulti, MultiValue, ToLuaMulti};
+use crate::value::{FromLuaMulti, ToLuaMulti};
#[cfg(feature = "async")]
use {futures_core::future::LocalBoxFuture, futures_util::future};
@@ -59,7 +59,7 @@ impl<'lua> Function<'lua> {
pub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(&self, args: A) -> Result<R> {
let lua = self.0.lua;
- let args = args.to_lua_multi(lua)?;
+ let mut args = args.to_lua_multi(lua)?;
let nargs = args.len() as c_int;
let results = unsafe {
@@ -69,7 +69,7 @@ impl<'lua> Function<'lua> {
ffi::lua_pushcfunction(lua.state, error_traceback);
let stack_start = ffi::lua_gettop(lua.state);
lua.push_ref(&self.0);
- for arg in args {
+ for arg in args.drain_all() {
lua.push_value(arg)?;
}
let ret = ffi::lua_pcall(lua.state, nargs, ffi::LUA_MULTRET, stack_start);
@@ -77,7 +77,7 @@ impl<'lua> Function<'lua> {
return Err(pop_error(lua.state, ret));
}
let nresults = ffi::lua_gettop(lua.state) - stack_start;
- let mut results = MultiValue::new();
+ let mut results = args; // Recycle MultiValue container
assert_stack(lua.state, 2);
for _ in 0..nresults {
results.push_front(lua.pop_value());