Avoid redundant string length function calls

Also switch to `std::string_view` as it is more generic and can handle more types (including
view types).

PR #21861.
This commit is contained in:
Chocobo1 2024-11-19 02:53:16 +08:00 committed by GitHub
parent 530631322d
commit 6ddde3f4b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 112 additions and 108 deletions

View file

@ -49,14 +49,14 @@ QString Utils::String::fromDouble(const double n, const int precision)
return QLocale::system().toString(std::floor(n * prec) / prec, 'f', precision);
}
QString Utils::String::fromLatin1(const std::string &string)
QString Utils::String::fromLatin1(const std::string_view string)
{
return QString::fromLatin1(string.c_str(), string.size());
return QString::fromLatin1(string.data(), string.size());
}
QString Utils::String::fromLocal8Bit(const std::string &string)
QString Utils::String::fromLocal8Bit(const std::string_view string)
{
return QString::fromLocal8Bit(string.c_str(), string.size());
return QString::fromLocal8Bit(string.data(), string.size());
}
QString Utils::String::wildcardToRegexPattern(const QString &pattern)