aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-12-14 00:27:01 +0100
committerShauren <shauren.trinity@gmail.com>2022-12-14 00:27:01 +0100
commit9d9e11f8ca8780e2336dd142bbeb15068da4ea72 (patch)
tree5aa77a9e74541829fc673b308e32dbe3c008571f
parent2d205506bfd3a2bb253db73b121fd147928811ba (diff)
Core/DataStores: Made DB2LoadInfo constexpr
-rw-r--r--src/common/DataStores/DB2FileLoader.cpp36
-rw-r--r--src/common/DataStores/DB2FileLoader.h4
-rw-r--r--src/server/shared/DataStores/DB2DatabaseLoader.cpp13
-rw-r--r--src/server/shared/DataStores/DB2DatabaseLoader.h3
4 files changed, 22 insertions, 34 deletions
diff --git a/src/common/DataStores/DB2FileLoader.cpp b/src/common/DataStores/DB2FileLoader.cpp
index c802b96d63b..c71e4b5d215 100644
--- a/src/common/DataStores/DB2FileLoader.cpp
+++ b/src/common/DataStores/DB2FileLoader.cpp
@@ -109,19 +109,11 @@ struct DB2IndexData
std::vector<DB2IndexEntry> Entries;
};
-DB2FileLoadInfo::DB2FileLoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta)
- : Fields(fields), FieldCount(fieldCount), Meta(meta)
-{
- TypesString.reserve(FieldCount);
- for (std::size_t i = 0; i < FieldCount; ++i)
- TypesString += char(Fields[i].Type);
-}
-
uint32 DB2FileLoadInfo::GetStringFieldCount(bool localizedOnly) const
{
uint32 stringFields = 0;
- for (char fieldType : TypesString)
- if (fieldType == FT_STRING || (fieldType == FT_STRING_NOT_LOCALIZED && !localizedOnly))
+ for (std::size_t i = 0; i < FieldCount; ++i)
+ if (Fields[i].Type == FT_STRING || (Fields[i].Type == FT_STRING_NOT_LOCALIZED && !localizedOnly))
++stringFields;
return stringFields;
@@ -428,7 +420,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**&
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_FLOAT:
*((float*)(&dataTable[offset])) = RecordGetFloat(rawRecord, x, z);
@@ -462,7 +454,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**&
break;
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
- _loadInfo->TypesString[fieldIndex], _fileName, _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
@@ -473,7 +465,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**&
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_INT:
*((uint32*)(&dataTable[offset])) = 0;
@@ -489,7 +481,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& indexTableSize, char**&
break;
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for parent field %s",
- _loadInfo->TypesString[fieldIndex], _fileName, _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
@@ -566,7 +558,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceStrings(char** indexTable, uint32 ind
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_FLOAT:
case FT_INT:
@@ -595,7 +587,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceStrings(char** indexTable, uint32 ind
}
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
- _loadInfo->TypesString[fieldIndex], _fileName, _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
@@ -1113,7 +1105,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_FLOAT:
*((float*)(&dataTable[offset])) = RecordGetFloat(rawRecord, x, z);
@@ -1147,7 +1139,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i
break;
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
- _loadInfo->TypesString[fieldIndex], _fileName, _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
@@ -1158,7 +1150,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_INT:
*((uint32*)(&dataTable[offset])) = 0;
@@ -1174,7 +1166,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& indexTableSize, char**& i
break;
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for parent field %s",
- _loadInfo->TypesString[fieldIndex], _fileName, _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
@@ -1263,7 +1255,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceStrings(char** indexTable, uint32 inde
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_FLOAT:
offset += 4;
@@ -1300,7 +1292,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceStrings(char** indexTable, uint32 inde
}
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
- _loadInfo->TypesString[fieldIndex], _fileName, _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _fileName, _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
diff --git a/src/common/DataStores/DB2FileLoader.h b/src/common/DataStores/DB2FileLoader.h
index 83e24716e2e..9e3f7c465f3 100644
--- a/src/common/DataStores/DB2FileLoader.h
+++ b/src/common/DataStores/DB2FileLoader.h
@@ -75,7 +75,8 @@ struct DB2FieldMeta
struct TC_COMMON_API DB2FileLoadInfo
{
- DB2FileLoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta);
+ constexpr explicit DB2FileLoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta)
+ : Fields(fields), FieldCount(fieldCount), Meta(meta) { }
uint32 GetStringFieldCount(bool localizedOnly) const;
std::pair<int32/*fieldIndex*/, int32/*arrayIndex*/> GetFieldIndexByName(char const* fieldName) const;
@@ -84,7 +85,6 @@ struct TC_COMMON_API DB2FileLoadInfo
DB2FieldMeta const* Fields;
std::size_t FieldCount;
DB2Meta const* Meta;
- std::string TypesString;
};
enum class DB2EncryptedSectionHandling
diff --git a/src/server/shared/DataStores/DB2DatabaseLoader.cpp b/src/server/shared/DataStores/DB2DatabaseLoader.cpp
index cd081dafaae..0435ba939c3 100644
--- a/src/server/shared/DataStores/DB2DatabaseLoader.cpp
+++ b/src/server/shared/DataStores/DB2DatabaseLoader.cpp
@@ -23,11 +23,6 @@
#include "Log.h"
#include <cstring>
-DB2LoadInfo::DB2LoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta, HotfixDatabaseStatements statement)
- : DB2FileLoadInfo(fields, fieldCount, meta), Statement(statement)
-{
-}
-
static char const* nullStr = "";
char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable, std::vector<char*>& stringPool)
@@ -102,7 +97,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[f])
+ switch (_loadInfo->Fields[f].Type)
{
case FT_FLOAT:
*((float*)(&dataValue[offset])) = fields[f].GetFloat();
@@ -153,7 +148,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
}
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
- _loadInfo->TypesString[f], _storageName.c_str(), _loadInfo->Fields[f].Name);
+ _loadInfo->Fields[f].Type, _storageName.c_str(), _loadInfo->Fields[f].Name);
break;
}
++f;
@@ -229,7 +224,7 @@ void DB2DatabaseLoader::LoadStrings(bool custom, LocaleConstant locale, uint32 r
{
for (uint32 z = 0; z < _loadInfo->Meta->Fields[x].ArraySize; ++z)
{
- switch (_loadInfo->TypesString[fieldIndex])
+ switch (_loadInfo->Fields[fieldIndex].Type)
{
case FT_FLOAT:
case FT_INT:
@@ -260,7 +255,7 @@ void DB2DatabaseLoader::LoadStrings(bool custom, LocaleConstant locale, uint32 r
break;
default:
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
- _loadInfo->TypesString[fieldIndex], _storageName.c_str(), _loadInfo->Fields[fieldIndex].Name);
+ _loadInfo->Fields[fieldIndex].Type, _storageName.c_str(), _loadInfo->Fields[fieldIndex].Name);
break;
}
++fieldIndex;
diff --git a/src/server/shared/DataStores/DB2DatabaseLoader.h b/src/server/shared/DataStores/DB2DatabaseLoader.h
index 4aefc503af0..2eadc450d87 100644
--- a/src/server/shared/DataStores/DB2DatabaseLoader.h
+++ b/src/server/shared/DataStores/DB2DatabaseLoader.h
@@ -26,7 +26,8 @@ enum HotfixDatabaseStatements : uint32;
struct TC_SHARED_API DB2LoadInfo : public DB2FileLoadInfo
{
- DB2LoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta, HotfixDatabaseStatements statement);
+ constexpr explicit DB2LoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta, HotfixDatabaseStatements statement)
+ : DB2FileLoadInfo(fields, fieldCount, meta), Statement(statement) { }
HotfixDatabaseStatements Statement;
};