Skip to content

Commit

Permalink
Minor optimisation to not lookup the length of a table every time, wh…
Browse files Browse the repository at this point in the history
…en appending to it.
  • Loading branch information
JonBooth78 committed Oct 16, 2023
1 parent a3de72d commit a227b3f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lua/LuaFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ static int l_filesystem_read_dir(lua_State *l)
lua_newtable(l);
int dirsTable = lua_gettop(l);

int dirs_len = 0;
int files_len = 0;
for (; !files.Finished(); files.Next()) {
const FileSystem::FileInfo &info = files.Current();

Expand All @@ -172,9 +174,9 @@ static int l_filesystem_read_dir(lua_State *l)
lua_setfield(l, -2, "mtime");

if (info.IsDir())
lua_rawseti(l, dirsTable, (int)lua_rawlen(l, dirsTable) + 1);
lua_rawseti(l, dirsTable, ++dirs_len);
else
lua_rawseti(l, filesTable, (int)lua_rawlen(l, filesTable) + 1);
lua_rawseti(l, filesTable, ++files_len);
}

return 2;
Expand Down

0 comments on commit a227b3f

Please sign in to comment.