summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-10-16 20:34:43 +0000
committerfrosch <frosch@openttd.org>2010-10-16 20:34:43 +0000
commit98250ad8da83fe6f842437bb614df28a1fe217c6 (patch)
treebfa52c0de54fa6c0a8c46d8b576555408ebcdc68 /src/core
parent82d4ffacff3398b44b2b16466f1305d607f0f57f (diff)
downloadopenttd-98250ad8da83fe6f842437bb614df28a1fe217c6.tar.xz
(svn r20951) -Codechange: Add SmallMap::Contains() and use it.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/smallmap_type.hpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp
index 8689447c1..7c0186689 100644
--- a/src/core/smallmap_type.hpp
+++ b/src/core/smallmap_type.hpp
@@ -55,6 +55,16 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
}
/**
+ * Tests whether a key is assigned in this map.
+ * @param key key to test
+ * @return true iff the item is present
+ */
+ FORCEINLINE bool Contains(const T &key)
+ {
+ return this->Find(key) != this->End();
+ }
+
+ /**
* Removes given pair from this map
* @param pair pair to remove
* @note it has to be pointer to pair in this map. It is overwritten by the last item.
@@ -90,7 +100,7 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
FORCEINLINE bool Insert(const T &key, const U &data)
{
- if (this->Find(key) != this->End()) return false;
+ if (this->Contains(key)) return false;
Pair *n = this->Append();
n->first = key;
n->second = data;