From 5e3b0674526b4645771569eec5c805ceeda36049 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 21 Apr 2020 13:59:01 +0200 Subject: [PATCH] Make Dictionary function parameters all passed by reference --- src/Collections/Dictionary.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Collections/Dictionary.hpp b/src/Collections/Dictionary.hpp index 7a74ed1..5918856 100644 --- a/src/Collections/Dictionary.hpp +++ b/src/Collections/Dictionary.hpp @@ -19,7 +19,7 @@ namespace Arbutils::Collections { _map.clear(); } - inline void Insert(KeyT key, ValueT value) { + inline void Insert(const KeyT& key, const ValueT& value) { auto v = _map.insert({key, value}); #ifndef NO_ASSERT if (!v.second) @@ -27,9 +27,10 @@ namespace Arbutils::Collections { #endif } - inline void Set(KeyT key, ValueT value) { _map[key] = value; } - [[nodiscard]] inline ValueT& Get(KeyT key) { + inline void Set(const KeyT& key, const ValueT& value) { _map[key] = value; } + + [[nodiscard]] inline ValueT& Get(const KeyT& key) { #ifndef NO_ASSERT auto find = _map.find(key); if (find == _map.end()) { @@ -41,7 +42,7 @@ namespace Arbutils::Collections { #endif } - [[nodiscard]] inline const ValueT& Get(KeyT key) const { + [[nodiscard]] inline const ValueT& Get(const KeyT& key) const { #ifndef NO_ASSERT auto find = _map.find(key); if (find == _map.end()) { @@ -53,7 +54,7 @@ namespace Arbutils::Collections { #endif } - inline bool TryGet(KeyT key, ValueT& out) const { + inline bool TryGet(const KeyT& key, ValueT& out) const { auto find = _map.find(key); if (find == _map.end()) { return false; @@ -62,16 +63,16 @@ namespace Arbutils::Collections { return true; } - inline void Remove(KeyT key){ + inline void Remove(const KeyT& key){ _map.erase(key); } [[nodiscard]] inline size_t Count() const { return _map.size(); } - inline bool Has(KeyT key) const noexcept { return _map.find(key) != _map.end(); } + inline bool Has(const KeyT& key) const noexcept { return _map.find(key) != _map.end(); } - inline ValueT& operator[](KeyT key) { return Get(key); } - inline const ValueT& operator[](KeyT key) const { return Get(key); } + inline ValueT& operator[](const KeyT& key) { return Get(key); } + inline const ValueT& operator[](const KeyT& key) const { return Get(key); } iterator begin() { return _map.begin(); } const_iterator begin() const { return _map.begin(); }