Utils: Avoid temporary strings when hashing links

Change-Id: I5d5cc5ed35fea7692d1c0bfdd9091928b5d46487
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-01-13 10:21:43 +01:00
parent 514a62b9b2
commit e373fe6aa9
2 changed files with 3 additions and 9 deletions

View File

@@ -41,11 +41,4 @@ Link Link::fromFilePath(const FilePath &filePath, bool canContainLineNumber, QSt
return Link{filePath.withNewPath(fileName.left(postfixPos)), lineColumn.line, lineColumn.column}; return Link{filePath.withNewPath(fileName.left(postfixPos)), lineColumn.line, lineColumn.column};
} }
size_t qHash(const Link &l)
{
QString s = l.targetFilePath.toString();
return qHash(s.append(':').append(QString::number(l.targetLine)).append(':')
.append(QString::number(l.targetColumn)));
}
} // namespace Utils } // namespace Utils

View File

@@ -46,6 +46,9 @@ public:
} }
bool operator!=(const Link &other) const { return !(*this == other); } bool operator!=(const Link &other) const { return !(*this == other); }
friend size_t qHash(const Link &l, uint seed = 0)
{ return qHashMulti(seed, l.targetFilePath, l.targetLine, l.targetColumn); }
int linkTextStart = -1; int linkTextStart = -1;
int linkTextEnd = -1; int linkTextEnd = -1;
@@ -54,8 +57,6 @@ public:
int targetColumn; int targetColumn;
}; };
QTCREATOR_UTILS_EXPORT size_t qHash(const Link &l);
using LinkHandler = std::function<void(const Link &)>; using LinkHandler = std::function<void(const Link &)>;
using Links = QList<Link>; using Links = QList<Link>;