summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2013-03-16 03:23:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-03-16 03:23:13 +0000
commitce7e278151d268f3cf55bcecd05f6be8c7e82e0f (patch)
treed49dd59e77a58db53384033b53177781d5c4cde7
parent041a075262ef5fc886e46fd4eec3dd79ee2e60c0 (diff)
parente81421e1cbd14876b7e6ce143ff70efb3673be99 (diff)
downloadframeworks_native-ce7e278151d268f3cf55bcecd05f6be8c7e82e0f.zip
frameworks_native-ce7e278151d268f3cf55bcecd05f6be8c7e82e0f.tar.gz
frameworks_native-ce7e278151d268f3cf55bcecd05f6be8c7e82e0f.tar.bz2
Merge "Add Vector::resize()" into jb-mr2-dev
-rw-r--r--include/utils/Vector.h8
-rw-r--r--include/utils/VectorImpl.h1
-rw-r--r--libs/utils/VectorImpl.cpp10
3 files changed, 18 insertions, 1 deletions
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index f3020d6..ed7b725 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -80,7 +80,13 @@ public:
//! sets the capacity. capacity can never be reduced less than size()
inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
- /*!
+ /*!
+ * set the size of the vector. items are appended with the default
+ * constructor, or removed from the end as needed.
+ */
+ inline ssize_t resize(size_t size) { return VectorImpl::resize(size); }
+
+ /*!
* C-style array access
*/
diff --git a/include/utils/VectorImpl.h b/include/utils/VectorImpl.h
index c4ec2ff..9bc50e6 100644
--- a/include/utils/VectorImpl.h
+++ b/include/utils/VectorImpl.h
@@ -64,6 +64,7 @@ public:
inline bool isEmpty() const { return mCount == 0; }
size_t capacity() const;
ssize_t setCapacity(size_t size);
+ ssize_t resize(size_t size);
/*! append/insert another vector or array */
ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
diff --git a/libs/utils/VectorImpl.cpp b/libs/utils/VectorImpl.cpp
index c3257bb..70f49de 100644
--- a/libs/utils/VectorImpl.cpp
+++ b/libs/utils/VectorImpl.cpp
@@ -343,6 +343,16 @@ ssize_t VectorImpl::setCapacity(size_t new_capacity)
return new_capacity;
}
+ssize_t VectorImpl::resize(size_t size) {
+ ssize_t result = NO_ERROR;
+ if (size > mCount) {
+ result = insertAt(mCount, size - mCount);
+ } else if (size < mCount) {
+ result = removeItemsAt(size, mCount - size);
+ }
+ return result < 0 ? result : size;
+}
+
void VectorImpl::release_storage()
{
if (mStorage) {