Make a toVariant() function on ArrayInit @override-unit-failures

Suggested by @smith.
Esse commit está contido em:
Jordan DeLong
2013-05-08 10:58:40 -07:00
commit de Sara Golemon
commit 4601297ae8
5 arquivos alterados com 45 adições e 8 exclusões
+14
Ver Arquivo
@@ -276,12 +276,26 @@ public:
return *this;
}
// Prefer toArray() in new code---it can save a null check when the
// compiler can't prove m_data hasn't changed.
ArrayData *create() {
ArrayData *ret = m_data;
m_data = nullptr;
return ret;
}
Array toArray() {
auto ptr = m_data;
m_data = nullptr;
return Array(ptr, Array::ArrayInitCtor::Tag);
}
Variant toVariant() {
auto ptr = m_data;
m_data = nullptr;
return Variant(ptr, Variant::ArrayInitCtor::Tag);
}
static ArrayData *CreateParams(int count, ...);
private:
+9
Ver Arquivo
@@ -82,6 +82,15 @@ class Array : protected SmartPtr<ArrayData> {
/* implicit */ Array(ArrayData *data) : ArrayBase(data) { }
/* implicit */ Array(CArrRef arr) : ArrayBase(arr.m_px) { }
/*
* Special constructor for use from ArrayInit that creates an Array
* without a null check.
*/
enum class ArrayInitCtor { Tag };
explicit Array(ArrayData* ad, ArrayInitCtor)
: ArrayBase(ad, ArrayBase::NonNull::Tag)
{}
// Move ctor
Array(Array&& src) : ArrayBase(std::move(src)) {
static_assert(sizeof(Array) == sizeof(ArrayBase), "Fix this.");
+10
Ver Arquivo
@@ -188,6 +188,16 @@ class Variant : private TypedValue {
Variant(const Variant *v) = delete;
Variant(Variant *v) = delete;
/*
* Creation constructor from ArrayInit that avoids a null check.
*/
enum class ArrayInitCtor { Tag };
explicit Variant(ArrayData* ad, ArrayInitCtor) {
m_type = KindOfArray;
m_data.parr = ad;
ad->incRefCount();
}
#ifdef INLINE_VARIANT_HELPER
inline ALWAYS_INLINE Variant(CVarRef v) { constructValHelper(v); }
inline ALWAYS_INLINE
+6
Ver Arquivo
@@ -53,6 +53,12 @@ public:
if (m_px) m_px->incRefCount();
}
enum class NonNull { Tag };
explicit SmartPtr(T* px, NonNull) : m_px(px) {
assert(px);
m_px->incRefCount();
}
// Move ctor
SmartPtr(SmartPtr&& src) : m_px(src.get()) {
src.m_px = nullptr;
+6 -8
Ver Arquivo
@@ -2309,12 +2309,10 @@ Array VMExecutionContext::debugBacktrace(bool skip /* = false */,
// the backtrace
if (parserFrame) {
bt.append(
Array(
ArrayInit(2)
.set(s_file, parserFrame->filename, true)
.set(s_line, parserFrame->lineNumber, true)
.create()
)
ArrayInit(2)
.set(s_file, parserFrame->filename, true)
.set(s_line, parserFrame->lineNumber, true)
.toVariant()
);
}
@@ -2360,7 +2358,7 @@ Array VMExecutionContext::debugBacktrace(bool skip /* = false */,
frame.set(s_function, s_include, true);
frame.set(s_args, Array::Create(parserFrame->filename), true);
}
bt.append(Array(frame.create()));
bt.append(frame.toVariant());
depth++;
}
}
@@ -2479,7 +2477,7 @@ Array VMExecutionContext::debugBacktrace(bool skip /* = false */,
frame.set(s_args, args, true);
}
bt.append(Array(frame.create()));
bt.append(frame.toVariant());
depth++;
}
return bt;