Skip to content

Commit

Permalink
修复文件名过长多音字过多导致卡死的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ehnap committed Jun 1, 2019
1 parent ae25cb4 commit 17e8c95
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 16 deletions.
Binary file modified galapp/gal.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions galapp/src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ ResultQueue QuickLaunchTable::queryResult(const QString& key)
ResultQueue s;
for (auto it = m_items.begin(); it != m_items.end(); it++)
{
QString k = it.key();
QString id = it.key();
Data v = it.value();
if (k.contains(key, Qt::CaseInsensitive) ||
if (PyData::GetInstance().isEqual(key.toUpper(), id) ||
v.displayName().contains(key, Qt::CaseInsensitive) ||
v.name().contains(key, Qt::CaseInsensitive))
s << v;
Expand Down
105 changes: 91 additions & 14 deletions galapp/src/pydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ QStringList PyData::queryPy(const QChar& key) const

QString PyData::getPy(const QString& key) const
{
//todo 串匹配算法需要调整,目前在文件名过长且多音字比较多的情况 QString 会卡死
QString nameID = key;
nameID.replace(" ", QString());
QString resultId;
Expand All @@ -45,25 +44,103 @@ QString PyData::getPy(const QString& key) const
if (uni >= 0x4E00 && uni <= 0x9FA5)
{
QStringList l = PyData::GetInstance().queryPy(nameID[i]);
QStringList resultList;
for (int i = 0; i < l.count(); i++)
resultId += l.count() > 1 ? "{" : "";
for (int i = 0; i < l.count() - 1; i++)
{
QStringList tempList = resultId.split("|");
for (int j = 0; j < tempList.count(); j++)
{
tempList[j] += l[i];
}
resultList += tempList;
resultId += l[i] + "|";
}
resultId = resultList.join("|");
resultId += l[l.count() - 1];
resultId += l.count() > 1 ? "}" : "";
}
else
{
if (resultId.contains("|"))
resultId = resultId.replace("|", nameID[i] + QString("|"));
else
resultId += nameID[i];
resultId += nameID[i];
}
}
return resultId;
}

bool PyData::isEqual(const QString& key, const QString& data) const
{
int iStart = 0;
int j = 0;
int k = 0;
int iKeyGuard = -1;
bool bStartMatch = false;
bool bTarget = false;
do
{
if (k >= key.length())
break;

if (bStartMatch)
{
if (key[k] == data[j])
{
k++;
if (k >= key.length())
{
bTarget = true;
break;
}
}
else if (data[j] == '{')
{
iKeyGuard = k;
}
else if (data[j] == '|')
{
do
{
j++;
} while (data[j] != '}');
}
else if (data[j] == '}')
{
iKeyGuard = -1;
}
else
{
// key[k] != data[j]
if (iKeyGuard == -1)
{
bStartMatch = false;
j = iStart;
k = 0;
}
else
{
k = iKeyGuard;
do
{
j++;
if (data[j] == '|')
break;

if (data[j] == '}')
{
bStartMatch = false;
j = iStart;
k = 0;
break;
}
} while (true);
}
}
}
else
{
k = 0;
if (key[k] == data[j])
{
iStart = j;
bStartMatch = true;
k++;
}
}
j++;
} while (j < data.count());

return bTarget;
}

1 change: 1 addition & 0 deletions galapp/src/pydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PyData
void init();
QStringList queryPy(const QChar& key) const;
QString getPy(const QString& key) const;
bool isEqual(const QString& a, const QString& b) const;

private:
PyData() {}
Expand Down

0 comments on commit 17e8c95

Please sign in to comment.