diff options
author | 2011-09-13 18:49:13 +0000 | |
---|---|---|
committer | 2011-09-13 18:49:13 +0000 | |
commit | a996fec40444e8b914cd84c17037f0c84301f717 (patch) | |
tree | 138d7cdf17cc4a3e052f5c34a1cd21245988f245 /gpu/include | |
parent | f3cf9429cc8f483bc5287ca09206a0fc81d98729 (diff) |
Use push_back_n() in place of multiple push_back()s
Review URL: http://codereview.appspot.com/5018041/
git-svn-id: http://skia.googlecode.com/svn/trunk@2260 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/include')
-rw-r--r-- | gpu/include/GrTArray.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/gpu/include/GrTArray.h b/gpu/include/GrTArray.h index c32a75e564..5477d25775 100644 --- a/gpu/include/GrTArray.h +++ b/gpu/include/GrTArray.h @@ -187,6 +187,11 @@ public: bool empty() const { return !fCount; } + /** + * Adds 1 new default-constructed T value and returns in by reference. Note + * the reference only remains valid until the next call that adds or removes + * elements. + */ T& push_back() { checkRealloc(1); new ((char*)fMemArray+sizeof(T)*fCount) T; @@ -194,13 +199,19 @@ public: return fItemArray[fCount-1]; } - void push_back_n(int n) { + /** + * Allocates n more default T values, and returns the address of the start + * of that new range. Note: this address is only valid until the next API + * call made on the array that might add or remove elements. + */ + T* push_back_n(int n) { GrAssert(n >= 0); checkRealloc(n); for (int i = 0; i < n; ++i) { new (fItemArray + fCount + i) T; } fCount += n; + return fItemArray + fCount - n; } void pop_back() { |