Improved file traversal to speed up search by pre-filtering masks (#416).
This commit is contained in:
@@ -341,42 +341,31 @@ local function onFileRegister(pos, length)
|
||||
end
|
||||
|
||||
local function ProcInFiles(startdir,mask,subdirs)
|
||||
local files = FileSysGetRecursive(startdir,subdirs,"*")
|
||||
local files = FileSysGetRecursive(startdir, subdirs, mask)
|
||||
local start = TimeGet()
|
||||
|
||||
-- mask could be a list, so generate a table with matching patterns
|
||||
-- accept "*.lua; .txt,.wlua" combinations
|
||||
local masks = {}
|
||||
for m in mask:gmatch("[^%s;,]+") do
|
||||
-- escape all special characters and replace (escaped) * with .*
|
||||
table.insert(masks, q(m):gsub("%%%*", ".*").."$")
|
||||
end
|
||||
for _,file in ipairs(files) do
|
||||
-- skip folders as these are included in the list as well
|
||||
if not IsDirectory(file) then
|
||||
local match = false
|
||||
for _, mask in ipairs(masks) do match = match or file:find(mask) end
|
||||
if match then
|
||||
findReplace.curfilename = file
|
||||
findReplace.curfilename = file
|
||||
|
||||
local filetext = FileRead(file)
|
||||
if filetext and not isBinary(filetext:sub(1, 2048)) then
|
||||
findReplace.oveditor:SetText(filetext)
|
||||
local filetext = FileRead(file)
|
||||
if filetext and not isBinary(filetext:sub(1, 2048)) then
|
||||
findReplace.oveditor:SetText(filetext)
|
||||
|
||||
if findReplace:FindStringAll(onFileRegister) then
|
||||
findReplace.files = findReplace.files + 1
|
||||
end
|
||||
if findReplace:FindStringAll(onFileRegister) then
|
||||
findReplace.files = findReplace.files + 1
|
||||
end
|
||||
|
||||
-- give time to the UI to refresh
|
||||
if TimeGet() - start > 0.25 then wx.wxSafeYield() end
|
||||
-- the IDE may be quitting after Yield or the tab may be closed,
|
||||
local ok, mgr = pcall(function() return ide:GetUIManager() end)
|
||||
-- so check to make sure the manager is still active
|
||||
if not (ok and mgr:GetPane(searchpanel):IsShown())
|
||||
-- and check that the search results tab is still open
|
||||
or not pcall(function() findReplace.reseditor:GetId() end) then
|
||||
return false
|
||||
end
|
||||
-- give time to the UI to refresh
|
||||
if TimeGet() - start > 0.25 then wx.wxSafeYield() end
|
||||
-- the IDE may be quitting after Yield or the tab may be closed,
|
||||
local ok, mgr = pcall(function() return ide:GetUIManager() end)
|
||||
-- so check to make sure the manager is still active
|
||||
if not (ok and mgr:GetPane(searchpanel):IsShown())
|
||||
-- and check that the search results tab is still open
|
||||
or not pcall(function() findReplace.reseditor:GetId() end) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
16
src/util.lua
16
src/util.lua
@@ -163,7 +163,13 @@ function FileSysGetRecursive(path, recursive, spec, skip)
|
||||
|
||||
-- recursion is done in all folders but only those folders that match
|
||||
-- the spec are returned. This is the pattern that matches the spec.
|
||||
local specmask = spec:gsub("%.", "%%."):gsub("%*", ".*").."$"
|
||||
-- Mask could be a list, so generate a table with matching patterns
|
||||
-- accept "*.lua; .txt,.wlua" combinations
|
||||
local masks = {}
|
||||
for m in spec:gmatch("[^%s;,]+") do
|
||||
-- escape all special characters and replace (escaped) * with .*
|
||||
table.insert(masks, EscapeMagic(m):gsub("%%%*", ".*").."$")
|
||||
end
|
||||
|
||||
local function getDir(path, spec)
|
||||
local dir = wx.wxDir(path)
|
||||
@@ -174,7 +180,13 @@ function FileSysGetRecursive(path, recursive, spec, skip)
|
||||
while found do
|
||||
if not skip or not file:find(skip) then
|
||||
local fname = wx.wxFileName(path, file):GetFullPath()
|
||||
if fname:find(specmask) then table.insert(content, fname..sep) end
|
||||
for _, mask in ipairs(masks) do
|
||||
if file:find(mask) then
|
||||
table.insert(content, fname..sep)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- check if this name already appears in the path earlier;
|
||||
-- Skip the processing if it does as it could lead to infinite
|
||||
-- recursion with circular references created by symlinks.
|
||||
|
||||
Reference in New Issue
Block a user