changeset 14436:ce2db37fe0f4 draft

(svn r18993) -Codechange: allow allocating multiple items in a SmallVector with one call.
author rubidium <rubidium@openttd.org>
date Wed, 03 Feb 2010 17:25:56 +0000
parents b7d4b37e625b
children a4c177e14a79
files src/core/smallvec_type.hpp src/newgrf_sound.cpp
diffstat 2 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -76,16 +76,20 @@
 
 	/**
 	 * 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];
 	}
 
 	/**
--- 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<SoundEntry, ORIGINAL_SAMPLE_COUNT> _sounds;
+static SmallVector<SoundEntry, 8> _sounds;
 
 
 /* Allocate a new Sound */