summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-05-17 23:31:44 +0200
committerMichael Lutz <michi@icosahedron.de>2020-05-21 20:02:34 +0200
commitf2b40f40aa7cbccaed20ec52b41d4704a45d8db1 (patch)
tree2f8268a7292118c9e460524a139ab85766ed3425
parent7309bdec48c70499301eb579991c2db6f7ef1d99 (diff)
downloadopenttd-f2b40f40aa7cbccaed20ec52b41d4704a45d8db1.tar.xz
Codechange: Replace SmallPair with std::pair.
std::pair is already the smallest possible pair, and it already handles non-POD types correctly.
-rw-r--r--src/core/smallmap_type.hpp30
-rw-r--r--src/fontcache.cpp4
-rw-r--r--src/linkgraph/linkgraph.h11
-rw-r--r--src/linkgraph/linkgraphjob.h4
-rw-r--r--src/newgrf.cpp2
-rw-r--r--src/newgrf_config.cpp4
-rw-r--r--src/newgrf_debug_gui.cpp2
-rw-r--r--src/newgrf_text.cpp2
-rw-r--r--src/vehicle.cpp2
9 files changed, 24 insertions, 37 deletions
diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp
index 478e7515a..931a4848b 100644
--- a/src/core/smallmap_type.hpp
+++ b/src/core/smallmap_type.hpp
@@ -11,40 +11,26 @@
#define SMALLMAP_TYPE_HPP
#include "smallvec_type.hpp"
+#include <utility>
/**
- * Simple pair of data. Both types have to be POD ("Plain Old Data")!
- * @tparam T Key type.
- * @tparam U Value type.
- */
-template <typename T, typename U>
-struct SmallPair {
- T first;
- U second;
-
- /** Initializes this Pair with data */
- inline SmallPair(const T &first, const U &second) : first(first), second(second) { }
- SmallPair() = default;
-};
-
-/**
- * Implementation of simple mapping class. Both types have to be POD ("Plain Old Data")!
- * It has inherited accessors from SmallVector().
+ * Implementation of simple mapping class.
+ * It has inherited accessors from std::vector().
* @tparam T Key type.
* @tparam U Value type.
* @tparam S Unit of allocation.
*
- * @see SmallVector
+ * @see std::vector
*/
template <typename T, typename U>
-struct SmallMap : std::vector<SmallPair<T, U> > {
- typedef ::SmallPair<T, U> Pair;
+struct SmallMap : std::vector<std::pair<T, U> > {
+ typedef std::pair<T, U> Pair;
typedef Pair *iterator;
typedef const Pair *const_iterator;
- /** Creates new SmallMap. Data are initialized in SmallVector constructor */
+ /** Creates new SmallMap. Data are initialized in std::vector constructor */
inline SmallMap() { }
- /** Data are freed in SmallVector destructor */
+ /** Data are freed in std::vector destructor */
inline ~SmallMap() { }
/**
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index 9102f356a..6cdac1fab 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -211,7 +211,7 @@ protected:
int req_size; ///< Requested font size.
int used_size; ///< Used font size.
- typedef SmallMap<uint32, SmallPair<size_t, const void*> > FontTable; ///< Table with font table cache
+ typedef SmallMap<uint32, std::pair<size_t, const void*> > FontTable; ///< Table with font table cache
FontTable font_tables; ///< Cached font tables.
/** Container for information about a glyph. */
@@ -434,7 +434,7 @@ const void *TrueTypeFontCache::GetFontTable(uint32 tag, size_t &length)
const void *result = this->InternalGetFontTable(tag, length);
- this->font_tables.Insert(tag, SmallPair<size_t, const void *>(length, result));
+ this->font_tables.Insert(tag, std::pair<size_t, const void *>(length, result));
return result;
}
diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h
index 997d94623..7362b7d56 100644
--- a/src/linkgraph/linkgraph.h
+++ b/src/linkgraph/linkgraph.h
@@ -17,6 +17,7 @@
#include "../cargotype.h"
#include "../date_func.h"
#include "linkgraph_type.h"
+#include <utility>
struct SaveLoad;
class LinkGraph;
@@ -188,20 +189,20 @@ public:
* to return something that implements operator->, but isn't a pointer
* from operator->. A fake pointer.
*/
- class FakePointer : public SmallPair<NodeID, Tedge_wrapper> {
+ class FakePointer : public std::pair<NodeID, Tedge_wrapper> {
public:
/**
* Construct a fake pointer from a pair of NodeID and edge.
* @param pair Pair to be "pointed" to (in fact shallow-copied).
*/
- FakePointer(const SmallPair<NodeID, Tedge_wrapper> &pair) : SmallPair<NodeID, Tedge_wrapper>(pair) {}
+ FakePointer(const std::pair<NodeID, Tedge_wrapper> &pair) : std::pair<NodeID, Tedge_wrapper>(pair) {}
/**
* Retrieve the pair by operator->.
* @return Pair being "pointed" to.
*/
- SmallPair<NodeID, Tedge_wrapper> *operator->() { return this; }
+ std::pair<NodeID, Tedge_wrapper> *operator->() { return this; }
};
public:
@@ -266,9 +267,9 @@ public:
* Dereference with operator*.
* @return Pair of current target NodeID and edge object.
*/
- SmallPair<NodeID, Tedge_wrapper> operator*() const
+ std::pair<NodeID, Tedge_wrapper> operator*() const
{
- return SmallPair<NodeID, Tedge_wrapper>(this->current, Tedge_wrapper(this->base[this->current]));
+ return std::pair<NodeID, Tedge_wrapper>(this->current, Tedge_wrapper(this->base[this->current]));
}
/**
diff --git a/src/linkgraph/linkgraphjob.h b/src/linkgraph/linkgraphjob.h
index 9344ea246..cd7ece4b1 100644
--- a/src/linkgraph/linkgraphjob.h
+++ b/src/linkgraph/linkgraphjob.h
@@ -160,9 +160,9 @@ public:
* @return Pair of the edge currently pointed to and the ID of its
* other end.
*/
- SmallPair<NodeID, Edge> operator*() const
+ std::pair<NodeID, Edge> operator*() const
{
- return SmallPair<NodeID, Edge>(this->current, Edge(this->base[this->current], this->base_anno[this->current]));
+ return std::pair<NodeID, Edge>(this->current, Edge(this->base[this->current], this->base_anno[this->current]));
}
/**
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index c422fe99c..c1b836481 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -8113,7 +8113,7 @@ static bool ChangeGRFParamValueNames(ByteReader *buf)
byte langid = buf->ReadByte();
const char *name_string = buf->ReadString();
- SmallPair<uint32, GRFText *> *val_name = _cur_parameter->value_names.Find(id);
+ std::pair<uint32, GRFText *> *val_name = _cur_parameter->value_names.Find(id);
if (val_name != _cur_parameter->value_names.End()) {
AddGRFTextToList(&val_name->second, langid, _cur.grfconfig->ident.grfid, false, name_string);
} else {
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index a0960350d..605bceca5 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -262,7 +262,7 @@ GRFParameterInfo::GRFParameterInfo(GRFParameterInfo &info) :
complete_labels(info.complete_labels)
{
for (uint i = 0; i < info.value_names.size(); i++) {
- SmallPair<uint32, GRFText *> *data = info.value_names.data() + i;
+ std::pair<uint32, GRFText *> *data = info.value_names.data() + i;
this->value_names.Insert(data->first, DuplicateGRFText(data->second));
}
}
@@ -273,7 +273,7 @@ GRFParameterInfo::~GRFParameterInfo()
CleanUpGRFText(this->name);
CleanUpGRFText(this->desc);
for (uint i = 0; i < this->value_names.size(); i++) {
- SmallPair<uint32, GRFText *> *data = this->value_names.data() + i;
+ std::pair<uint32, GRFText *> *data = this->value_names.data() + i;
CleanUpGRFText(data->second);
}
}
diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp
index a8ba3d526..19757646d 100644
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -804,7 +804,7 @@ GrfSpecFeature GetGrfSpecFeature(VehicleType type)
/** Window used for aligning sprites. */
struct SpriteAlignerWindow : Window {
- typedef SmallPair<int16, int16> XyOffs; ///< Pair for x and y offsets of the sprite before alignment. First value contains the x offset, second value y offset.
+ typedef std::pair<int16, int16> XyOffs; ///< Pair for x and y offsets of the sprite before alignment. First value contains the x offset, second value y offset.
SpriteID current_sprite; ///< The currently shown sprite.
Scrollbar *vscroll;
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index c08877198..134511944 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -196,7 +196,7 @@ struct UnmappedChoiceList : ZeroedMemoryAllocator {
/** Clean everything up. */
~UnmappedChoiceList()
{
- for (SmallPair<byte, char *> p : this->strings) {
+ for (std::pair<byte, char *> p : this->strings) {
free(p.second);
}
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index ae5af64a1..72ef5a31a 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2278,7 +2278,7 @@ void Vehicle::GetConsistFreeCapacities(SmallMap<CargoID, uint> &capacities) cons
{
for (const Vehicle *v = this; v != nullptr; v = v->Next()) {
if (v->cargo_cap == 0) continue;
- SmallPair<CargoID, uint> *pair = capacities.Find(v->cargo_type);
+ std::pair<CargoID, uint> *pair = capacities.Find(v->cargo_type);
if (pair == capacities.End()) {
capacities.push_back({v->cargo_type, v->cargo_cap - v->cargo.StoredCount()});
} else {