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

Unified Diff: include/core/SkTArray.h

Issue 1677103002: Revert of SkTArray to move when moving. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | include/ports/SkFontMgr_indirect.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTArray.h
diff --git a/include/core/SkTArray.h b/include/core/SkTArray.h
index 86c5eaacf02535953f4581c50d2293c6f746974f..bd255e3868add398809d233b107b76d299b33fd3 100644
--- a/include/core/SkTArray.h
+++ b/include/core/SkTArray.h
@@ -8,7 +8,6 @@
#ifndef SkTArray_DEFINED
#define SkTArray_DEFINED
-#include "../private/SkTLogic.h"
#include "../private/SkTemplates.h"
#include "SkTypes.h"
@@ -16,6 +15,42 @@
#include <utility>
template <typename T, bool MEM_COPY = false> class SkTArray;
+
+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) {
+ sk_careful_memcpy(self->fMemArray, array, self->fCount * sizeof(T));
+}
+template<typename T>
+inline void copyAndDelete(SkTArray<T, true>* self, char* newMemArray) {
+ sk_careful_memcpy(newMemArray, self->fMemArray, self->fCount * sizeof(T));
+}
+
+template<typename T>
+inline void copy(SkTArray<T, false>* self, int dst, int src) {
+ new (&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) {
+ new (self->fItemArray + i) T(array[i]);
+ }
+}
+template<typename T>
+inline void copyAndDelete(SkTArray<T, false>* self, char* newMemArray) {
+ for (int i = 0; i < self->fCount; ++i) {
+ new (newMemArray + sizeof(T) * i) T(self->fItemArray[i]);
+ self->fItemArray[i].~T();
+ }
+}
+
+}
+
template <typename T, bool MEM_COPY> void* operator new(size_t, SkTArray<T, MEM_COPY>*, int);
/** When MEM_COPY is true T will be bit copied when moved.
@@ -70,7 +105,7 @@
fCount = 0;
this->checkRealloc((int)array.count());
fCount = array.count();
- this->copy(static_cast<const T*>(array.fMemArray));
+ SkTArrayExt::copy(this, static_cast<const T*>(array.fMemArray));
return *this;
}
@@ -115,7 +150,7 @@
int delta = count - fCount;
this->checkRealloc(delta);
fCount = count;
- this->copy(array);
+ SkTArrayExt::copy(this, array);
}
void removeShuffle(int n) {
@@ -124,7 +159,8 @@
fCount = newCount;
fItemArray[n].~T();
if (n != newCount) {
- this->move(n, newCount);
+ SkTArrayExt::copy(this, n, newCount);
+ fItemArray[newCount].~T();
}
}
@@ -386,38 +422,10 @@
fMemArray = sk_malloc_throw(fAllocCount * sizeof(T));
}
- this->copy(array);
+ SkTArrayExt::copy(this, array);
}
private:
- /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage.
- * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage.
- */
- template <bool E = MEM_COPY> SK_WHEN(E, void) copy(const T* src) {
- sk_careful_memcpy(fMemArray, src, fCount * sizeof(T));
- }
- template <bool E = MEM_COPY> SK_WHEN(E, void) move(int dst, int src) {
- memcpy(&fItemArray[dst], &fItemArray[src], sizeof(T));
- }
- template <bool E = MEM_COPY> SK_WHEN(E, void) move(char* dst) {
- sk_careful_memcpy(dst, fMemArray, fCount * sizeof(T));
- }
-
- template <bool E = MEM_COPY> SK_WHEN(!E, void) copy(const T* src) {
- for (int i = 0; i < fCount; ++i) {
- new (fItemArray + i) T(src[i]);
- }
- }
- template <bool E = MEM_COPY> SK_WHEN(!E, void) move(int dst, int src) {
- new (&fItemArray[dst]) T(std::move(fItemArray[src]));
- fItemArray[src].~T();
- }
- template <bool E = MEM_COPY> SK_WHEN(!E, void) move(char* dst) {
- for (int i = 0; i < fCount; ++i) {
- new (dst + sizeof(T) * i) T(std::move(fItemArray[i]));
- fItemArray[i].~T();
- }
- }
static const int gMIN_ALLOC_COUNT = 8;
@@ -455,7 +463,7 @@
newMemArray = (char*) sk_malloc_throw(fAllocCount*sizeof(T));
}
- this->move(newMemArray);
+ SkTArrayExt::copyAndDelete<T>(this, newMemArray);
if (fMemArray != fPreAllocMemArray) {
sk_free(fMemArray);
@@ -465,6 +473,14 @@
}
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*);
int fReserveCount;
int fCount;
« no previous file with comments | « no previous file | include/ports/SkFontMgr_indirect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698