mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/DataStores: Reduce the number of string copies when loading db2 hotfixes
This commit is contained in:
@@ -5418,7 +5418,7 @@ void SpellMgr::LoadSpellInfoTargetCaps()
|
||||
ApplySpellFix({ 205472 }, [](SpellInfo* spellInfo)
|
||||
{
|
||||
spellInfo->_LoadSqrtTargetLimit(8, 0, {}, EFFECT_1, {}, {});
|
||||
}
|
||||
});
|
||||
|
||||
// Flamestrike
|
||||
ApplySpellFix({ 2120 }, [](SpellInfo* spellInfo)
|
||||
|
||||
@@ -65,7 +65,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
|
||||
if (stringFields)
|
||||
stringPool.reserve(std::max<uint64>(stringPool.capacity(), stringPool.size() + stringFields * result->GetRowCount() + 1));
|
||||
|
||||
uint32 newRecords = 0;
|
||||
std::size_t newRecords = 0;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -126,7 +126,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
|
||||
localeStr = nullStr;
|
||||
|
||||
// Value in database in main table field must be for enUS locale
|
||||
if (char* str = AddString(&slot->Str[LOCALE_enUS], fields[f].GetString()))
|
||||
if (char* str = AddString(&slot->Str[LOCALE_enUS], fields[f].GetStringView()))
|
||||
stringPool.push_back(str);
|
||||
|
||||
offset += sizeof(LocalizedString);
|
||||
@@ -137,7 +137,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
|
||||
char const** slot = (char const**)(&dataValue[offset]);
|
||||
|
||||
// Value in database in main table field must be for enUS locale
|
||||
if (char* str = AddString(slot, fields[f].GetString()))
|
||||
if (char* str = AddString(slot, fields[f].GetStringView()))
|
||||
stringPool.push_back(str);
|
||||
else
|
||||
*slot = nullStr;
|
||||
@@ -146,8 +146,8 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
|
||||
_loadInfo->Fields[f].Type, _storageName.c_str(), _loadInfo->Fields[f].Name);
|
||||
ABORT_MSG("Unknown format character '%c' found in " STRING_VIEW_FMT " meta for field %s",
|
||||
_loadInfo->Fields[f].Type, STRING_VIEW_FMT_ARG(_storageName), _loadInfo->Fields[f].Name);
|
||||
break;
|
||||
}
|
||||
++f;
|
||||
@@ -169,7 +169,7 @@ char* DB2DatabaseLoader::Load(bool custom, uint32& records, char**& indexTable,
|
||||
memcpy(dataTable, tempDataTable, newRecords * recordSize);
|
||||
|
||||
// insert new records to index table
|
||||
for (uint32 i = 0; i < newRecords; ++i)
|
||||
for (std::size_t i = 0; i < newRecords; ++i)
|
||||
{
|
||||
uint32 newId = newIndexes[i];
|
||||
indexTable[newId] = &dataTable[i * recordSize];
|
||||
@@ -245,7 +245,7 @@ void DB2DatabaseLoader::LoadStrings(bool custom, LocaleConstant locale, uint32 r
|
||||
{
|
||||
// fill only not filled entries
|
||||
LocalizedString* db2str = (LocalizedString*)(&dataValue[offset]);
|
||||
if (char* str = AddString(&db2str->Str[locale], fields[1 + stringFieldNumInRecord].GetString()))
|
||||
if (char* str = AddString(&db2str->Str[locale], fields[1 + stringFieldNumInRecord].GetStringView()))
|
||||
stringPool.push_back(str);
|
||||
|
||||
++stringFieldNumInRecord;
|
||||
@@ -256,8 +256,8 @@ void DB2DatabaseLoader::LoadStrings(bool custom, LocaleConstant locale, uint32 r
|
||||
offset += sizeof(char*);
|
||||
break;
|
||||
default:
|
||||
ABORT_MSG("Unknown format character '%c' found in %s meta for field %s",
|
||||
_loadInfo->Fields[fieldIndex].Type, _storageName.c_str(), _loadInfo->Fields[fieldIndex].Name);
|
||||
ABORT_MSG("Unknown format character '%c' found in " STRING_VIEW_FMT " meta for field %s",
|
||||
_loadInfo->Fields[fieldIndex].Type, STRING_VIEW_FMT_ARG(_storageName), _loadInfo->Fields[fieldIndex].Name);
|
||||
break;
|
||||
}
|
||||
++fieldIndex;
|
||||
@@ -272,12 +272,12 @@ void DB2DatabaseLoader::LoadStrings(bool custom, LocaleConstant locale, uint32 r
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
char* DB2DatabaseLoader::AddString(char const** holder, std::string const& value)
|
||||
char* DB2DatabaseLoader::AddString(char const** holder, std::string_view value)
|
||||
{
|
||||
if (!value.empty())
|
||||
{
|
||||
char* str = new char[value.length() + 1];
|
||||
memcpy(str, value.c_str(), value.length());
|
||||
memcpy(str, value.data(), value.length());
|
||||
str[value.length()] = '\0';
|
||||
*holder = str;
|
||||
return str;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define DB2_DATABASE_LOADER_H
|
||||
|
||||
#include "DB2FileLoader.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
enum HotfixDatabaseStatements : uint32;
|
||||
@@ -35,14 +35,14 @@ struct TC_SHARED_API DB2LoadInfo : public DB2FileLoadInfo
|
||||
class TC_SHARED_API DB2DatabaseLoader
|
||||
{
|
||||
public:
|
||||
DB2DatabaseLoader(std::string const& storageName, DB2LoadInfo const* loadInfo) : _storageName(storageName), _loadInfo(loadInfo) { }
|
||||
DB2DatabaseLoader(std::string_view storageName, DB2LoadInfo const* loadInfo) : _storageName(storageName), _loadInfo(loadInfo) { }
|
||||
|
||||
char* Load(bool custom, uint32& records, char**& indexTable, std::vector<char*>& stringPool, uint32& minId);
|
||||
void LoadStrings(bool custom, LocaleConstant locale, uint32 records, char** indexTable, std::vector<char*>& stringPool);
|
||||
static char* AddString(char const** holder, std::string const& value);
|
||||
static char* AddString(char const** holder, std::string_view value);
|
||||
|
||||
private:
|
||||
std::string const& _storageName;
|
||||
std::string_view _storageName;
|
||||
DB2LoadInfo const* _loadInfo;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user