#include "SkChunkAlloc.h"
#include "SkRecords.h"
+#include "SkTLogic.h"
#include "SkTemplates.h"
// SkRecord (REC-ord) represents a sequence of SkCanvas calls, saved for future use.
}
fTypes[fCount] = T::kType;
- return fRecords[fCount++].set(this->alloc<T>());
+ return fRecords[fCount++].set(this->allocCommand<T>());
}
// Replace the i-th command with a new command of type T.
this->mutate(i, destroyer);
fTypes[i] = T::kType;
- return fRecords[i].set(this->alloc<T>());
+ return fRecords[i].set(this->allocCommand<T>());
}
// Replace the i-th command with a new command of type T.
SkASSERT(proofOfAdoption == fRecords[i].ptr<Existing>());
fTypes[i] = T::kType;
- return fRecords[i].set(this->alloc<T>());
+ return fRecords[i].set(this->allocCommand<T>());
}
private:
uint8_t fType;
};
+ // No point in allocating any more than one of an empty struct.
+ // We could just return NULL but it's sort of confusing to return NULL on success.
+ template <typename T>
+ SK_WHEN(SkTIsEmpty<T>, T*) allocCommand() {
+ static T singleton;
+ return &singleton;
+ }
+
+ template <typename T>
+ SK_WHEN(!SkTIsEmpty<T>, T*) allocCommand() { return this->alloc<T>(); }
+
// An untyped pointer to some bytes in fAlloc. This is the interface for polymorphic dispatch:
// visit() and mutate() work with the parallel fTypes array to do the work of a vtable.
struct Record {
/** Convenience specialization of SkTIntegralConstant. */
template <bool b> struct SkTBool : SkTIntegralConstant<bool, b> { };
+/** Pre-C++11 version of std::is_empty<T>. */
+template <typename T>
+class SkTIsEmpty {
+ struct Derived : public T { char unused; };
+public:
+ static const bool value = sizeof(Derived) == sizeof(char);
+};
+
/** Pre-C++11 version of std::true_type. */
typedef SkTBool<true> SkTrue;