Optimize Lua::create_table to use reference thread if possible

This commit is contained in:
Alex Orlenko 2022-10-18 01:09:35 +01:00
parent de69d10d73
commit 65396a910f
No known key found for this signature in database
GPG key ID: 4C150C250863B96D

View file

@ -1457,11 +1457,15 @@ impl Lua {
/// Lua may use these hints to preallocate memory for the new table.
pub fn create_table_with_capacity(&self, narr: c_int, nrec: c_int) -> Result<Table> {
unsafe {
if self.unlikely_memory_error() {
push_table(self.ref_thread(), narr, nrec, false)?;
return Ok(Table(self.pop_ref_thread()));
}
let _sg = StackGuard::new(self.state);
check_stack(self.state, 3)?;
let protect = !self.unlikely_memory_error();
push_table(self.state, narr, nrec, protect)?;
push_table(self.state, narr, nrec, true)?;
Ok(Table(self.pop_ref()))
}
}