mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Enable the use of std::string_view for find in ObjectRepository
This commit is contained in:
@@ -19,6 +19,24 @@
|
|||||||
|
|
||||||
namespace OpenRCT2::String
|
namespace OpenRCT2::String
|
||||||
{
|
{
|
||||||
|
struct Hash
|
||||||
|
{
|
||||||
|
using is_transparent = void;
|
||||||
|
|
||||||
|
size_t operator()(const char* txt) const
|
||||||
|
{
|
||||||
|
return std::hash<std::string_view>{}(txt);
|
||||||
|
}
|
||||||
|
size_t operator()(std::string_view txt) const
|
||||||
|
{
|
||||||
|
return std::hash<std::string_view>{}(txt);
|
||||||
|
}
|
||||||
|
size_t operator()(const std::string& txt) const
|
||||||
|
{
|
||||||
|
return std::hash<std::string>{}(txt);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
std::string toStd(const utf8* str);
|
std::string toStd(const utf8* str);
|
||||||
std::string toUtf8(std::wstring_view src);
|
std::string toUtf8(std::wstring_view src);
|
||||||
std::wstring toWideChar(std::string_view src);
|
std::wstring toWideChar(std::string_view src);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ struct ObjectEntryEqual
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using ObjectIdentifierMap = std::unordered_map<std::string, size_t>;
|
using ObjectIdentifierMap = std::unordered_map<std::string, size_t, String::Hash, std::equal_to<>>;
|
||||||
using ObjectEntryMap = std::unordered_map<RCTObjectEntry, size_t, ObjectEntryHash, ObjectEntryEqual>;
|
using ObjectEntryMap = std::unordered_map<RCTObjectEntry, size_t, ObjectEntryHash, ObjectEntryEqual>;
|
||||||
|
|
||||||
class ObjectFileIndex final : public FileIndex<ObjectRepositoryItem>
|
class ObjectFileIndex final : public FileIndex<ObjectRepositoryItem>
|
||||||
@@ -235,7 +235,7 @@ public:
|
|||||||
|
|
||||||
const ObjectRepositoryItem* FindObject(std::string_view identifier) const override final
|
const ObjectRepositoryItem* FindObject(std::string_view identifier) const override final
|
||||||
{
|
{
|
||||||
auto kvp = _newItemMap.find(std::string(identifier));
|
auto kvp = _newItemMap.find(identifier);
|
||||||
if (kvp != _newItemMap.end())
|
if (kvp != _newItemMap.end())
|
||||||
{
|
{
|
||||||
return &_items[kvp->second];
|
return &_items[kvp->second];
|
||||||
|
|||||||
Reference in New Issue
Block a user