Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1276)

Unified Diff: include/core/SkTArray.h

Issue 208153008: Add test for SkTArray. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | tests/TArrayTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTArray.h
===================================================================
--- include/core/SkTArray.h (revision 13875)
+++ include/core/SkTArray.h (working copy)
@@ -17,6 +17,10 @@
namespace SkTArrayExt {
template<typename T>
+inline void copy(SkTArray<T, true>* self, int dst, int src) {
+ memcpy(&self->fItemArray[dst], &self->fItemArray[src], sizeof(T));
+}
+template<typename T>
inline void copy(SkTArray<T, true>* self, const T* array) {
memcpy(self->fMemArray, array, self->fCount * sizeof(T));
}
@@ -26,6 +30,10 @@
}
template<typename T>
+inline void copy(SkTArray<T, false>* self, int dst, int src) {
+ SkNEW_PLACEMENT_ARGS(&self->fItemArray[dst], T, (self->fItemArray[src]));
+}
+template<typename T>
inline void copy(SkTArray<T, false>* self, const T* array) {
for (int i = 0; i < self->fCount; ++i) {
SkNEW_PLACEMENT_ARGS(self->fItemArray + i, T, (array[i]));
@@ -140,8 +148,17 @@
int delta = count - fCount;
this->checkRealloc(delta);
fCount = count;
- for (int i = 0; i < count; ++i) {
- SkTArrayExt::copy(this, array);
+ SkTArrayExt::copy(this, array);
+ }
+
+ void removeShuffle(int n) {
+ SkASSERT(n < fCount);
+ int newCount = fCount - 1;
+ fCount = newCount;
+ fItemArray[n].~T();
+ if (n != newCount) {
+ SkTArrayExt::copy(this, n, newCount);
+ fItemArray[newCount].~T();
}
}
@@ -427,9 +444,11 @@
friend void* operator new<T>(size_t, SkTArray*, int);
+ template<typename X> friend void SkTArrayExt::copy(SkTArray<X, true>* that, int dst, int src);
template<typename X> friend void SkTArrayExt::copy(SkTArray<X, true>* that, const X*);
template<typename X> friend void SkTArrayExt::copyAndDelete(SkTArray<X, true>* that, char*);
+ template<typename X> friend void SkTArrayExt::copy(SkTArray<X, false>* that, int dst, int src);
template<typename X> friend void SkTArrayExt::copy(SkTArray<X, false>* that, const X*);
template<typename X> friend void SkTArrayExt::copyAndDelete(SkTArray<X, false>* that, char*);
« no previous file with comments | « gyp/tests.gypi ('k') | tests/TArrayTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698