diff options
author | peter1138 <peter1138@openttd.org> | 2008-05-25 16:12:13 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2008-05-25 16:12:13 +0000 |
commit | da8bb14ceca9f306c4df4430ba1647bdde5afe47 (patch) | |
tree | 0f76f6fdcba28b90a10723f0c23c8155fddc3822 /src/misc | |
parent | 32380e257ce18d4cf3409ce9f1b8c5b43b3610ed (diff) | |
download | openttd-da8bb14ceca9f306c4df4430ba1647bdde5afe47.tar.xz |
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/smallvec.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/misc/smallvec.h b/src/misc/smallvec.h index 984d634ac..7f85cc96a 100644 --- a/src/misc/smallvec.h +++ b/src/misc/smallvec.h @@ -19,6 +19,29 @@ struct SmallVector { } /** + * Remove all items from the list. + */ + void Clear() + { + /* In fact we just reset the item counter avoiding the need to + * probably reallocate the same amount of memory the list was + * previously using. */ + this->items = 0; + } + + /** + * Compact the list down to the smallest block size boundary. + */ + void Compact() + { + uint capacity = Align(this->items, S); + if (capacity >= this->capacity) return; + + this->capacity = capacity; + this->data = ReallocT(this->data, this->capacity); + } + + /** * Append an item and return it. */ T *Append() @@ -31,6 +54,14 @@ struct SmallVector { return &this->data[this->items++]; } + /** + * Get the number of items in the list. + */ + uint Length() const + { + return this->items; + } + const T *Begin() const { return this->data; @@ -60,6 +91,16 @@ struct SmallVector { { return &this->data[index]; } + + const T &operator[](uint index) const + { + return this->data[index]; + } + + T &operator[](uint index) + { + return this->data[index]; + } }; #endif /* SMALLVEC_H */ |