mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-11 00:44:33 +00:00
Create getRefIds
This commit is contained in:
parent
c59032fd66
commit
7b909c8d24
@ -21,17 +21,18 @@ namespace ESM
|
|||||||
|
|
||||||
const std::string emptyString;
|
const std::string emptyString;
|
||||||
|
|
||||||
Misc::NotNullPtr<const std::string> getOrInsertString(std::string_view id, bool insert)
|
Misc::ScopeGuarded<StringsSet>& getRefIds()
|
||||||
{
|
{
|
||||||
static Misc::ScopeGuarded<StringsSet> refIds;
|
static Misc::ScopeGuarded<StringsSet> refIds;
|
||||||
const auto locked = refIds.lock();
|
return refIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
Misc::NotNullPtr<const std::string> getOrInsertString(std::string_view id)
|
||||||
|
{
|
||||||
|
const auto locked = getRefIds().lock();
|
||||||
auto it = locked->find(id);
|
auto it = locked->find(id);
|
||||||
if (it == locked->end())
|
if (it == locked->end())
|
||||||
{
|
|
||||||
if (!insert)
|
|
||||||
return &emptyString;
|
|
||||||
it = locked->emplace(id).first;
|
it = locked->emplace(id).first;
|
||||||
}
|
|
||||||
return &*it;
|
return &*it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ namespace ESM
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringRefId::StringRefId(std::string_view value)
|
StringRefId::StringRefId(std::string_view value)
|
||||||
: mValue(getOrInsertString(value, true))
|
: mValue(getOrInsertString(value))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,11 +137,12 @@ namespace ESM
|
|||||||
|
|
||||||
std::optional<StringRefId> StringRefId::deserializeExisting(std::string_view value)
|
std::optional<StringRefId> StringRefId::deserializeExisting(std::string_view value)
|
||||||
{
|
{
|
||||||
auto string = getOrInsertString(value, false);
|
const auto locked = getRefIds().lock();
|
||||||
if (string->empty())
|
auto it = locked->find(value);
|
||||||
|
if (it == locked->end())
|
||||||
return {};
|
return {};
|
||||||
StringRefId id;
|
StringRefId id;
|
||||||
id.mValue = string;
|
id.mValue = &*it;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user