Skip to content

Commit 4226c18

Browse files
liyigang1Johnson-zs
authored andcommitted
perf: cache resolved indexed directories to avoid repeated resolution
Made the `dirs` variable in `defaultIndexedDirectory()` static const so that `getResolvedIndexedDirectories()` is only called once. This avoids redundant directory resolution on every invocation of the default indexed directory lookup. 将`defaultIndexedDirectory()`中的`dirs`变量声明为static const, 使`getResolvedIndexedDirectories()`仅被调用一次,避免每次查找默认 索引目录时重复进行目录解析。 Log: 缓存已解析的索引目录避免重复解析 PMS: https://pms.uniontech.com/bug-view-361809.html Influence: 减少重复调用时的冗余文件系统操作,提升频繁查询默认索引目录的搜索场景性能。需确认应用重启后仍能正确加载索引目录配置变更,以及静态初始化不存在线程安全问题。
1 parent 5eceb2a commit 4226c18

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/dfm-search/dfm-search-lib/utils/searchutility.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ QStringList defaultContentSearchExtensions()
514514

515515
QStringList defaultIndexedDirectory()
516516
{
517-
const QStringList &dirs = getResolvedIndexedDirectories();
517+
static const QStringList dirs = getResolvedIndexedDirectories();
518518

519519
if (dirs.isEmpty()) {
520520
return QStringList();
@@ -615,7 +615,7 @@ bool isPathInContentIndexDirectory(const QString &path)
615615
if (!isContentIndexAvailable())
616616
return false;
617617

618-
static const QStringList &kDirs = DFMSEARCH::Global::defaultIndexedDirectory();
618+
static const QStringList kDirs = DFMSEARCH::Global::defaultIndexedDirectory();
619619
return isPathInAnyDirectory(path, kDirs);
620620
}
621621

@@ -673,7 +673,7 @@ bool isPathInOcrTextIndexDirectory(const QString &path)
673673
if (!isOcrTextIndexAvailable())
674674
return false;
675675

676-
static const QStringList &kDirs = DFMSEARCH::Global::defaultIndexedDirectory();
676+
static const QStringList kDirs = DFMSEARCH::Global::defaultIndexedDirectory();
677677
return isPathInAnyDirectory(path, kDirs);
678678
}
679679

@@ -714,11 +714,11 @@ bool isPathInFileNameIndexDirectory(const QString &path)
714714
if (!isFileNameIndexDirectoryAvailable())
715715
return false;
716716

717-
static const QStringList &kBlackPaths = defaultBlacklistPaths();
717+
static const QStringList kBlackPaths = defaultBlacklistPaths();
718718
if (BlacklistMatcher::isPathBlacklisted(path, kBlackPaths))
719719
return false;
720720

721-
static const QStringList &kIndexedDirs = DFMSEARCH::Global::defaultIndexedDirectory();
721+
static const QStringList kIndexedDirs = DFMSEARCH::Global::defaultIndexedDirectory();
722722
return isPathInAnyDirectory(path, kIndexedDirs);
723723
}
724724

0 commit comments

Comments
 (0)