Simplify SkTArray move()
Switch from using template enable_if to use 'if constexpr' making
the code clearer.
Change-Id: Ifa97cf99c38d4a195dcb439f0aadf8a3e2eedf13
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/592738
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h
index 9672b84..7eeceea 100644
--- a/include/private/SkTArray.h
+++ b/include/private/SkTArray.h
@@ -549,23 +549,25 @@
}
}
- template <bool E = MEM_MOVE> std::enable_if_t<E, void> move(int dst, int src) {
- memcpy(static_cast<void*>(&fItemArray[dst]),
- static_cast<void*>(&fItemArray[src]),
- sizeof(T));
- }
- template <bool E = MEM_MOVE> std::enable_if_t<E, void> move(void* dst) {
- sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T));
+ void move(int dst, int src) {
+ if constexpr (MEM_MOVE) {
+ memcpy(static_cast<void*>(&fItemArray[dst]),
+ static_cast<void*>(&fItemArray[src]),
+ sizeof(T));
+ } else {
+ new (&fItemArray[dst]) T(std::move(fItemArray[src]));
+ fItemArray[src].~T();
+ }
}
- template <bool E = MEM_MOVE> std::enable_if_t<!E, void> move(int dst, int src) {
- new (&fItemArray[dst]) T(std::move(fItemArray[src]));
- fItemArray[src].~T();
- }
- template <bool E = MEM_MOVE> std::enable_if_t<!E, void> move(void* dst) {
- for (int i = 0; i < this->count(); ++i) {
- new (static_cast<char*>(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i]));
- fItemArray[i].~T();
+ void move(void* dst) {
+ if constexpr (MEM_MOVE) {
+ sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T));
+ } else {
+ for (int i = 0; i < this->count(); ++i) {
+ new (static_cast<char*>(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i]));
+ fItemArray[i].~T();
+ }
}
}