From e0ce993c61506679f8b3a4ef110001c8f68ca4b4 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Wed, 5 Feb 2020 19:32:07 +0100 Subject: [PATCH] [fix] Don't waste time on dir/file attributes in subdirs (#5819) An awful lot of effort was wasted getting attributes just for getting a count of the number of files/directories in subdirectories. Getting the count is pretty fast. Getting all the attributes is not, and in this context we don't even use the attributes. See and for discussion. --- frontend/ui/widget/filechooser.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index b91e87250..36a3c2761 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -56,12 +56,16 @@ function FileChooser:init() end return true end - self.list = function(path, dirs, files) + self.list = function(path, dirs, files, count_only) -- lfs.dir directory without permission will give error local ok, iter, dir_obj = pcall(lfs.dir, path) if ok then for f in iter, dir_obj do - if self.show_hidden or not string.match(f, "^%.[^.]") then + if count_only then + if self.show_hidden or not util.stringStartsWith(f, ".") then + table.insert(dirs, true) + end + elseif self.show_hidden or not string.match(f, "^%.[^.]") then local filename = path.."/"..f local attributes = lfs.attributes(filename) if attributes ~= nil then @@ -211,7 +215,7 @@ function FileChooser:genItemTableFromPath(path) local sub_dirs = {} local dir_files = {} local subdir_path = self.path.."/"..dir.name - self.list(subdir_path, sub_dirs, dir_files) + self.list(subdir_path, sub_dirs, dir_files, true) local num_items = #sub_dirs + #dir_files local istr = ffiUtil.template(N_("1 item", "%1 items", num_items), num_items) local text