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
9 changed files with 112 additions and 108 deletions

View File

@@ -28,6 +28,7 @@
#include "geoipdatabase.h"
#include <QByteArray>
#include <QDateTime>
#include <QDebug>
#include <QFile>
@@ -41,7 +42,7 @@ namespace
{
const qint32 MAX_FILE_SIZE = 67108864; // 64MB
const quint32 MAX_METADATA_SIZE = 131072; // 128KB
const char METADATA_BEGIN_MARK[] = "\xab\xcd\xefMaxMind.com";
const QByteArray METADATA_BEGIN_MARK = QByteArrayLiteral("\xab\xcd\xefMaxMind.com");
const char DATA_SECTION_SEPARATOR[16] = {0};
enum class DataType
@@ -309,7 +310,7 @@ QVariantHash GeoIPDatabase::readMetadata() const
{
if (m_size > MAX_METADATA_SIZE)
index += (m_size - MAX_METADATA_SIZE); // from begin of all data
auto offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
auto offset = static_cast<quint32>(index + METADATA_BEGIN_MARK.size());
const QVariant metadata = readDataField(offset);
if (metadata.userType() == QMetaType::QVariantHash)
return metadata.toHash();