From fe57aec2a434b394c020d17d3b8f6769ee008414 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 30 Dec 2022 00:04:02 +0100 Subject: [PATCH 1/2] Move ESM::RefId comment to make sure IDEs recognize it and show in tooltips --- components/esm/refid.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index 6bc49313d0..7394bf8ba2 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -8,11 +8,11 @@ namespace ESM { + // RefId is used to represent an Id that identifies an ESM record. These Ids can then be used in + // ESM::Stores to find the actual record. These Ids can be serialized/de-serialized, stored on disk and remain + // valid. They are used by ESM files, by records to reference other ESM records. struct RefId { - // This structure is used to represent an Id that identifies an ESM record. These Ids can then be used in - // ESM::Stores to find the actual record. These Ids can be serialized/de-serialized, stored on disk and remain - // valid. They are used by ESM files, by records to reference other ESM records. const static RefId sEmpty; bool empty() const { return mId.empty(); } void swap(RefId& rhs) { mId.swap(rhs.mId); } From 755067f0f39215f2a329ce46559135fd251f3f1f Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 30 Dec 2022 00:32:04 +0100 Subject: [PATCH 2/2] Remove redundant ESM::RefId member functions --- apps/openmw/mwworld/weather.cpp | 3 ++- components/esm/refid.cpp | 5 ---- components/esm/refid.hpp | 7 ++--- components/esm3/magiceffects.hpp | 37 ++++++++++++--------------- components/misc/strings/algorithm.hpp | 10 -------- 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 22bf4117d0..d4d74dd5ec 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -22,6 +22,7 @@ #include "esmstore.hpp" #include "player.hpp" +#include #include namespace MWWorld @@ -932,7 +933,7 @@ namespace MWWorld ESM::WeatherState state; state.load(reader); - mCurrentRegion.swap(state.mCurrentRegion); + std::swap(mCurrentRegion, state.mCurrentRegion); mTimePassed = state.mTimePassed; mFastForward = state.mFastForward; mWeatherUpdateTime = state.mWeatherUpdateTime; diff --git a/components/esm/refid.cpp b/components/esm/refid.cpp index ec18c4c642..08199df93d 100644 --- a/components/esm/refid.cpp +++ b/components/esm/refid.cpp @@ -16,11 +16,6 @@ namespace ESM return Misc::StringUtils::ciLess(mId, rhs.mId); } - bool RefId::operator>(const RefId& rhs) const - { - return Misc::StringUtils::ciGreater(mId, rhs.mId); - } - std::ostream& operator<<(std::ostream& os, const RefId& refId) { os << refId.getRefIdString(); diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index 7394bf8ba2..cd3bef27dd 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -1,6 +1,6 @@ #ifndef OPENMW_COMPONENTS_ESM_REFID_HPP #define OPENMW_COMPONENTS_ESM_REFID_HPP -#include + #include #include #include @@ -14,11 +14,12 @@ namespace ESM struct RefId { const static RefId sEmpty; + bool empty() const { return mId.empty(); } - void swap(RefId& rhs) { mId.swap(rhs.mId); } + bool operator==(const RefId& rhs) const; + bool operator<(const RefId& rhs) const; - bool operator>(const RefId& rhs) const; friend std::ostream& operator<<(std::ostream& os, const RefId& dt); diff --git a/components/esm3/magiceffects.hpp b/components/esm3/magiceffects.hpp index e528ba3a87..3f141355c8 100644 --- a/components/esm3/magiceffects.hpp +++ b/components/esm3/magiceffects.hpp @@ -2,8 +2,10 @@ #define COMPONENTS_ESM_MAGICEFFECTS_H #include + #include #include +#include namespace ESM { @@ -29,30 +31,25 @@ namespace ESM { } - bool operator==(const SummonKey& other) const - { - return mEffectId == other.mEffectId && mSourceId == other.mSourceId && mEffectIndex == other.mEffectIndex; - } - - bool operator<(const SummonKey& other) const - { - if (mEffectId < other.mEffectId) - return true; - if (mEffectId > other.mEffectId) - return false; - - if (mSourceId < other.mSourceId) - return true; - if (mSourceId > other.mSourceId) - return false; - - return mEffectIndex < other.mEffectIndex; - } - int mEffectId; ESM::RefId mSourceId; int mEffectIndex; }; + + inline auto makeTupleRef(const SummonKey& value) noexcept + { + return std::tie(value.mEffectId, value.mSourceId, value.mEffectIndex); + } + + inline bool operator==(const SummonKey& l, const SummonKey& r) noexcept + { + return makeTupleRef(l) == makeTupleRef(r); + } + + inline bool operator<(const SummonKey& l, const SummonKey& r) noexcept + { + return makeTupleRef(l) < makeTupleRef(r); + } } #endif diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index 8141058da7..1e1eba30a9 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -20,16 +20,6 @@ namespace Misc::StringUtils return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharLess()); } - struct CiCharGreater - { - bool operator()(char x, char y) const { return toLower(x) > toLower(y); } - }; - - inline bool ciGreater(std::string_view x, std::string_view y) - { - return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharGreater()); - } - inline bool ciEqual(std::string_view x, std::string_view y) { if (std::size(x) != std::size(y))