From c75f19f40b047b829321dd0386d391940b942644 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 3 Feb 2010 17:25:56 +0000 Subject: [PATCH] (svn r18993) -Codechange: allow allocating multiple items in a SmallVector with one call. --- src/core/smallvec_type.hpp | 12 ++++++++---- src/newgrf_sound.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index 5e4e17365f..832ba47926 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]; } /** diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp index a386f5b58b..48623647ea 100644 --- a/src/newgrf_sound.cpp +++ b/src/newgrf_sound.cpp @@ -18,7 +18,7 @@ #include "sound_func.h" #include "core/mem_func.hpp" -static SmallVector _sounds; +static SmallVector _sounds; /* Allocate a new Sound */