@@ -166,7 +166,6 @@ void ElunaLoader::LoadScripts()
166166
167167int ElunaLoader::LoadBytecodeChunk (lua_State* /* L*/ , uint8* bytes, size_t len, BytecodeBuffer* buffer)
168168{
169- buffer->reserve (buffer->size () + len);
170169 buffer->insert (buffer->end (), bytes, bytes + len);
171170 return 0 ;
172171}
@@ -231,7 +230,8 @@ void ElunaLoader::ReadFiles(lua_State* L, std::string path)
231230
232231 // was file, try add
233232 std::string filename = dir_iter->path ().filename ().generic_string ();
234- ProcessScript (L, filename, fullpath, mapId);
233+ size_t filesize = fs::file_size (dir_iter->path ());
234+ ProcessScript (L, filename, filesize, fullpath, mapId);
235235 }
236236 }
237237 }
@@ -272,7 +272,7 @@ bool ElunaLoader::CompileScript(lua_State* L, LuaScript& script)
272272 return true ;
273273}
274274
275- void ElunaLoader::ProcessScript (lua_State* L, std::string filename, const std::string& fullpath, int32 mapId)
275+ void ElunaLoader::ProcessScript (lua_State* L, std::string filename, const size_t & filesize, const std::string& fullpath, int32 mapId)
276276{
277277 ELUNA_LOG_DEBUG (" [Eluna]: ProcessScript checking file `%s`" , fullpath.c_str ());
278278
@@ -293,6 +293,7 @@ void ElunaLoader::ProcessScript(lua_State* L, std::string filename, const std::s
293293 script.filename = filename;
294294 script.filepath = fullpath;
295295 script.modulepath = fullpath.substr (0 , fullpath.length () - filename.length () - ext.length ());
296+ script.bytecode .reserve (filesize);
296297 script.mapId = mapId;
297298
298299 // if compilation fails, we don't add the script
0 commit comments