summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-02-03 17:25:56 +0000
committerrubidium <rubidium@openttd.org>2010-02-03 17:25:56 +0000
commitc75f19f40b047b829321dd0386d391940b942644 (patch)
treef9ffd2148bd599845a8940b30a9a2785f70b455c /src/core
parente437362c7babbdc4d4dff812e88b77bb521be6c5 (diff)
downloadopenttd-c75f19f40b047b829321dd0386d391940b942644.tar.xz
(svn r18993) -Codechange: allow allocating multiple items in a SmallVector with one call.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/smallvec_type.hpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index 5e4e17365..832ba4792 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -76,16 +76,20 @@ public:
/**
* Append an item and return it.
+ * @param to_add the number of items to append
* @return pointer to newly allocated item
*/
- FORCEINLINE T *Append()
+ FORCEINLINE T *Append(size_t to_add = 1)
{
- if (this->items == this->capacity) {
- this->capacity += S;
+ size_t begin = this->items;
+ this->items += to_add;
+
+ if (this->items > this->capacity) {
+ this->capacity = Align(this->items, S);
this->data = ReallocT(this->data, this->capacity);
}
- return &this->data[this->items++];
+ return &this->data[begin];
}
/**