mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 06:39:42 +00:00
Don't lowerCase twice when getting globals
This commit is contained in:
parent
613453c799
commit
31b2112e4a
2 changed files with 13 additions and 12 deletions
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#include <components/esm3/esmreader.hpp>
|
#include <components/esm3/esmreader.hpp>
|
||||||
#include <components/esm3/esmwriter.hpp>
|
#include <components/esm3/esmwriter.hpp>
|
||||||
#include <components/misc/strings/lower.hpp>
|
|
||||||
|
|
||||||
#include "esmstore.hpp"
|
#include "esmstore.hpp"
|
||||||
|
|
||||||
|
@ -12,7 +11,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
Globals::Collection::const_iterator Globals::find(std::string_view name) const
|
Globals::Collection::const_iterator Globals::find(std::string_view name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = mVariables.find(Misc::StringUtils::lowerCase(name));
|
Collection::const_iterator iter = mVariables.find(name);
|
||||||
|
|
||||||
if (iter == mVariables.end())
|
if (iter == mVariables.end())
|
||||||
throw std::runtime_error("unknown global variable: " + std::string{ name });
|
throw std::runtime_error("unknown global variable: " + std::string{ name });
|
||||||
|
@ -22,7 +21,7 @@ namespace MWWorld
|
||||||
|
|
||||||
Globals::Collection::iterator Globals::find(std::string_view name)
|
Globals::Collection::iterator Globals::find(std::string_view name)
|
||||||
{
|
{
|
||||||
Collection::iterator iter = mVariables.find(Misc::StringUtils::lowerCase(name));
|
Collection::iterator iter = mVariables.find(name);
|
||||||
|
|
||||||
if (iter == mVariables.end())
|
if (iter == mVariables.end())
|
||||||
throw std::runtime_error("unknown global variable: " + std::string{ name });
|
throw std::runtime_error("unknown global variable: " + std::string{ name });
|
||||||
|
@ -38,23 +37,23 @@ namespace MWWorld
|
||||||
|
|
||||||
for (const ESM::Global& esmGlobal : globals)
|
for (const ESM::Global& esmGlobal : globals)
|
||||||
{
|
{
|
||||||
mVariables.insert(std::make_pair(Misc::StringUtils::lowerCase(esmGlobal.mId.getRefIdString()), esmGlobal));
|
mVariables.emplace(esmGlobal.mId.getRefIdString(), esmGlobal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESM::Variant& Globals::operator[](std::string_view name) const
|
const ESM::Variant& Globals::operator[](std::string_view name) const
|
||||||
{
|
{
|
||||||
return find(Misc::StringUtils::lowerCase(name))->second.mValue;
|
return find(name)->second.mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::Variant& Globals::operator[](std::string_view name)
|
ESM::Variant& Globals::operator[](std::string_view name)
|
||||||
{
|
{
|
||||||
return find(Misc::StringUtils::lowerCase(name))->second.mValue;
|
return find(name)->second.mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char Globals::getType(std::string_view name) const
|
char Globals::getType(std::string_view name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = mVariables.find(Misc::StringUtils::lowerCase(name));
|
Collection::const_iterator iter = mVariables.find(name);
|
||||||
|
|
||||||
if (iter == mVariables.end())
|
if (iter == mVariables.end())
|
||||||
return ' ';
|
return ' ';
|
||||||
|
@ -80,10 +79,10 @@ namespace MWWorld
|
||||||
|
|
||||||
void Globals::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
|
void Globals::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
|
||||||
{
|
{
|
||||||
for (Collection::const_iterator iter(mVariables.begin()); iter != mVariables.end(); ++iter)
|
for (const auto& variable : mVariables)
|
||||||
{
|
{
|
||||||
writer.startRecord(ESM::REC_GLOB);
|
writer.startRecord(ESM::REC_GLOB);
|
||||||
iter->second.save(writer);
|
variable.second.save(writer);
|
||||||
writer.endRecord(ESM::REC_GLOB);
|
writer.endRecord(ESM::REC_GLOB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +98,7 @@ namespace MWWorld
|
||||||
// Deleted globals can't appear there, so isDeleted will be ignored here.
|
// Deleted globals can't appear there, so isDeleted will be ignored here.
|
||||||
global.load(reader, isDeleted);
|
global.load(reader, isDeleted);
|
||||||
|
|
||||||
Collection::iterator iter = mVariables.find(Misc::StringUtils::lowerCase(global.mId.getRefIdString()));
|
Collection::iterator iter = mVariables.find(global.mId.getRefIdString());
|
||||||
if (iter != mVariables.end())
|
if (iter != mVariables.end())
|
||||||
iter->second = global;
|
iter->second = global;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#ifndef GAME_MWWORLD_GLOBALS_H
|
#ifndef GAME_MWWORLD_GLOBALS_H
|
||||||
#define GAME_MWWORLD_GLOBALS_H
|
#define GAME_MWWORLD_GLOBALS_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <components/esm3/loadglob.hpp>
|
#include <components/esm3/loadglob.hpp>
|
||||||
|
#include <components/misc/strings/algorithm.hpp>
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
|
@ -27,7 +28,8 @@ namespace MWWorld
|
||||||
class Globals
|
class Globals
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::string, ESM::Global> Collection;
|
using Collection
|
||||||
|
= std::unordered_map<std::string, ESM::Global, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>;
|
||||||
|
|
||||||
Collection mVariables; // type, value
|
Collection mVariables; // type, value
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue