mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 22:15:35 +00:00
Merge branch 'global_view' into 'master'
Don't lowerCase twice when getting globals See merge request OpenMW/openmw!2676
This commit is contained in:
commit
c28eba53e4
2 changed files with 13 additions and 12 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <components/esm3/esmreader.hpp>
|
||||
#include <components/esm3/esmwriter.hpp>
|
||||
#include <components/misc/strings/lower.hpp>
|
||||
|
||||
#include "esmstore.hpp"
|
||||
|
||||
|
@ -12,7 +11,7 @@ namespace MWWorld
|
|||
{
|
||||
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())
|
||||
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)
|
||||
{
|
||||
Collection::iterator iter = mVariables.find(Misc::StringUtils::lowerCase(name));
|
||||
Collection::iterator iter = mVariables.find(name);
|
||||
|
||||
if (iter == mVariables.end())
|
||||
throw std::runtime_error("unknown global variable: " + std::string{ name });
|
||||
|
@ -38,23 +37,23 @@ namespace MWWorld
|
|||
|
||||
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
|
||||
{
|
||||
return find(Misc::StringUtils::lowerCase(name))->second.mValue;
|
||||
return find(name)->second.mValue;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
Collection::const_iterator iter = mVariables.find(Misc::StringUtils::lowerCase(name));
|
||||
Collection::const_iterator iter = mVariables.find(name);
|
||||
|
||||
if (iter == mVariables.end())
|
||||
return ' ';
|
||||
|
@ -80,10 +79,10 @@ namespace MWWorld
|
|||
|
||||
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);
|
||||
iter->second.save(writer);
|
||||
variable.second.save(writer);
|
||||
writer.endRecord(ESM::REC_GLOB);
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +98,7 @@ namespace MWWorld
|
|||
// Deleted globals can't appear there, so isDeleted will be ignored here.
|
||||
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())
|
||||
iter->second = global;
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#ifndef GAME_MWWORLD_GLOBALS_H
|
||||
#define GAME_MWWORLD_GLOBALS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <components/esm3/loadglob.hpp>
|
||||
#include <components/misc/strings/algorithm.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
@ -27,7 +28,8 @@ namespace MWWorld
|
|||
class Globals
|
||||
{
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue