Split lvalPtr() into createLvalPtr/getLvalPtr()
Callers are always passing a constant to choose one or the other, so make them distinct methods.
Esse commit está contido em:
@@ -194,9 +194,12 @@ bool ArrayData::equal(const ArrayData *v2, bool strict) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayData *ArrayData::lvalPtr(StringData* k, Variant *&ret, bool copy,
|
||||
bool create) {
|
||||
throw FatalErrorException("Unimplemented ArrayData::lvalPtr");
|
||||
ArrayData *ArrayData::createLvalPtr(StringData* k, Variant *&ret, bool copy) {
|
||||
throw FatalErrorException("Unimplemented ArrayData::createLvalPtr");
|
||||
}
|
||||
|
||||
ArrayData *ArrayData::getLvalPtr(StringData* k, Variant *&ret, bool copy) {
|
||||
throw FatalErrorException("Unimplemented ArrayData::getLvalPtr");
|
||||
}
|
||||
|
||||
ArrayData *ArrayData::add(int64_t k, CVarRef v, bool copy) {
|
||||
|
||||
@@ -250,8 +250,8 @@ public:
|
||||
* the dynamic property array in ObjectData or the local cache array
|
||||
* in ShardMap.
|
||||
*/
|
||||
virtual ArrayData *lvalPtr(StringData* k, Variant *&ret, bool copy,
|
||||
bool create);
|
||||
virtual ArrayData *createLvalPtr(StringData* k, Variant *&ret, bool copy);
|
||||
virtual ArrayData *getLvalPtr(StringData* k, Variant *&ret, bool copy);
|
||||
|
||||
/**
|
||||
* Setting a value at specified key. If "copy" is true, make a copy first
|
||||
@@ -297,7 +297,8 @@ public:
|
||||
CVarRef get(CVarRef k, bool error = false) const;
|
||||
ArrayData *lval(CStrRef k, Variant *&ret, bool copy, bool checkExist=false);
|
||||
ArrayData *lval(CVarRef k, Variant *&ret, bool copy, bool checkExist=false);
|
||||
ArrayData *lvalPtr(CStrRef k, Variant *&ret, bool copy, bool create);
|
||||
ArrayData *createLvalPtr(CStrRef k, Variant *&ret, bool copy);
|
||||
ArrayData *getLvalPtr(CStrRef k, Variant *&ret, bool copy);
|
||||
ArrayData *set(CStrRef k, CVarRef v, bool copy);
|
||||
ArrayData *set(CVarRef k, CVarRef v, bool copy);
|
||||
ArrayData *setRef(CStrRef k, CVarRef v, bool copy);
|
||||
|
||||
@@ -77,10 +77,15 @@ inline ArrayData* ArrayData::lval(CVarRef k, Variant *&ret, bool copy,
|
||||
: lval(getStringKey(cell), ret, copy, checkExist);
|
||||
}
|
||||
|
||||
inline ArrayData *ArrayData::lvalPtr(CStrRef k, Variant *&ret, bool copy,
|
||||
bool create) {
|
||||
inline
|
||||
ArrayData *ArrayData::createLvalPtr(CStrRef k, Variant *&ret, bool copy) {
|
||||
assert(IsValidKey(k));
|
||||
return lvalPtr(k.get(), ret, copy, create);
|
||||
return createLvalPtr(k.get(), ret, copy);
|
||||
}
|
||||
|
||||
inline ArrayData *ArrayData::getLvalPtr(CStrRef k, Variant *&ret, bool copy) {
|
||||
assert(IsValidKey(k));
|
||||
return getLvalPtr(k.get(), ret, copy);
|
||||
}
|
||||
|
||||
inline ArrayData* ArrayData::set(CStrRef k, CVarRef v, bool copy) {
|
||||
|
||||
@@ -1103,12 +1103,14 @@ ArrayData* HphpArray::lval(StringData* key, Variant*& ret, bool copy,
|
||||
return copyImpl()->addLvalImpl(key, prehash, &ret);
|
||||
}
|
||||
|
||||
ArrayData *HphpArray::lvalPtr(StringData* key, Variant*& ret, bool copy,
|
||||
bool create) {
|
||||
strhash_t prehash = key->hash();
|
||||
ArrayData *HphpArray::createLvalPtr(StringData* key, Variant*& ret, bool copy) {
|
||||
HphpArray* a = !copy ? this : copyImpl();
|
||||
if (create) return a->addLvalImpl(key, prehash, &ret);
|
||||
auto pos = a->find(key, prehash);
|
||||
return a->addLvalImpl(key, key->hash(), &ret);
|
||||
}
|
||||
|
||||
ArrayData *HphpArray::getLvalPtr(StringData* key, Variant*& ret, bool copy) {
|
||||
HphpArray* a = !copy ? this : copyImpl();
|
||||
auto pos = a->find(key, key->hash());
|
||||
if (pos != (ssize_t)ElmIndEmpty) {
|
||||
Elm* e = &a->m_data[pos];
|
||||
ret = &tvAsVariant(&e->data);
|
||||
|
||||
@@ -83,7 +83,8 @@ public:
|
||||
using ArrayData::get;
|
||||
using ArrayData::lval;
|
||||
using ArrayData::lvalNew;
|
||||
using ArrayData::lvalPtr;
|
||||
using ArrayData::createLvalPtr;
|
||||
using ArrayData::getLvalPtr;
|
||||
using ArrayData::set;
|
||||
using ArrayData::setRef;
|
||||
using ArrayData::add;
|
||||
@@ -128,8 +129,8 @@ public:
|
||||
ArrayData* lvalNew(Variant*& ret, bool copy);
|
||||
|
||||
// overrides ArrayData
|
||||
ArrayData* lvalPtr(StringData* k, Variant*& ret, bool copy,
|
||||
bool create);
|
||||
ArrayData* createLvalPtr(StringData* k, Variant*& ret, bool copy);
|
||||
ArrayData* getLvalPtr(StringData* k, Variant*& ret, bool copy);
|
||||
|
||||
// implements ArrayData
|
||||
ArrayData* set(int64_t k, CVarRef v, bool copy);
|
||||
|
||||
@@ -419,8 +419,11 @@ ArrayData *ArrayShell::lvalNew(Variant *&ret, bool copy) {
|
||||
return this;
|
||||
}
|
||||
|
||||
ArrayData *ArrayShell::lvalPtr(StringData* k, Variant *&ret, bool copy,
|
||||
bool create) {
|
||||
ArrayData *ArrayShell::createLvalPtr(StringData* k, Variant *&ret, bool copy) {
|
||||
NOT_IMPLEMENTED();
|
||||
}
|
||||
|
||||
ArrayData *ArrayShell::getLvalPtr(StringData* k, Variant *&ret, bool copy) {
|
||||
NOT_IMPLEMENTED();
|
||||
}
|
||||
|
||||
|
||||
@@ -489,9 +489,10 @@ public:
|
||||
* the dynamic property array in ObjectData or the local cache array
|
||||
* in ShardMap.
|
||||
*/
|
||||
virtual ArrayData *lvalPtr(StringData* k, Variant *&ret,
|
||||
bool copy,
|
||||
bool create) FOLLY_OVERRIDE;
|
||||
virtual ArrayData *createLvalPtr(StringData* k, Variant *&ret, bool copy)
|
||||
FOLLY_OVERRIDE;
|
||||
virtual ArrayData *getLvalPtr(StringData* k, Variant *&ret, bool copy)
|
||||
FOLLY_OVERRIDE;
|
||||
|
||||
/**
|
||||
* Setting a value at specified key. If "copy" is true, make a copy first
|
||||
|
||||
@@ -217,8 +217,7 @@ Variant* ObjectData::o_realProp(CStrRef propName, int flags,
|
||||
if (!o_properties.get()) {
|
||||
thiz->initDynProps();
|
||||
}
|
||||
o_properties.get()->lvalPtr(propName,
|
||||
*(Variant**)(&ret), false, true);
|
||||
o_properties.get()->createLvalPtr(propName, *(Variant**)(&ret), false);
|
||||
return (Variant*)ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ public:
|
||||
using ArrayData::get;
|
||||
using ArrayData::lval;
|
||||
using ArrayData::lvalNew;
|
||||
using ArrayData::lvalPtr;
|
||||
using ArrayData::set;
|
||||
using ArrayData::setRef;
|
||||
using ArrayData::add;
|
||||
|
||||
@@ -486,16 +486,16 @@ Variant Array::rvalAt(CVarRef key, ACCESSPARAMS_IMPL) const {
|
||||
return Array::rvalAtRef(key, flags);
|
||||
}
|
||||
|
||||
Variant *Array::lvalPtr(CStrRef key, bool forWrite, bool create) {
|
||||
if (create) {
|
||||
if (!m_px) ArrayBase::operator=(ArrayData::Create());
|
||||
return &lvalAt(key, AccessFlags::Key);
|
||||
}
|
||||
Variant *Array::createLvalPtr(CStrRef key, bool forWrite) {
|
||||
if (!m_px) ArrayBase::operator=(ArrayData::Create());
|
||||
return &lvalAt(key, AccessFlags::Key);
|
||||
}
|
||||
|
||||
Variant *Array::getLvalPtr(CStrRef key, bool forWrite) {
|
||||
Variant *ret = nullptr;
|
||||
if (m_px) {
|
||||
ArrayData *escalated = m_px->lvalPtr(key, ret,
|
||||
forWrite && m_px->getCount() > 1,
|
||||
false);
|
||||
ArrayData *escalated = m_px->getLvalPtr(key, ret,
|
||||
forWrite && m_px->getCount() > 1);
|
||||
if (escalated != m_px) ArrayBase::operator=(escalated);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -297,7 +297,8 @@ class Array : protected SmartPtr<ArrayData> {
|
||||
return *ret;
|
||||
}
|
||||
|
||||
Variant *lvalPtr(CStrRef key, bool forWrite, bool create);
|
||||
Variant *createLvalPtr(CStrRef key, bool forWrite);
|
||||
Variant *getLvalPtr(CStrRef key, bool forWrite);
|
||||
|
||||
Variant &lvalAt();
|
||||
|
||||
|
||||
@@ -1985,10 +1985,18 @@ Variant &Variant::lvalRef(CVarRef k, Variant& tmp, ACCESSPARAMS_IMPL) {
|
||||
return Variant::LvalAtImpl0<CVarRef>(this, k, &tmp, false, flags);
|
||||
}
|
||||
|
||||
Variant *Variant::lvalPtr(CStrRef key, bool forWrite, bool create) {
|
||||
Variant *Variant::createLvalPtr(CStrRef key, bool forWrite) {
|
||||
Variant *t = m_type == KindOfRef ? m_data.pref->var() : this;
|
||||
if (t->m_type == KindOfArray) {
|
||||
return t->asArrRef().lvalPtr(key, forWrite, create);
|
||||
return t->asArrRef().createLvalPtr(key, forWrite);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Variant *Variant::getLvalPtr(CStrRef key, bool forWrite) {
|
||||
Variant *t = m_type == KindOfRef ? m_data.pref->var() : this;
|
||||
if (t->m_type == KindOfArray) {
|
||||
return t->asArrRef().getLvalPtr(key, forWrite);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -807,7 +807,8 @@ class Variant : private TypedValue {
|
||||
return *ret;
|
||||
}
|
||||
|
||||
Variant *lvalPtr(CStrRef key, bool forWrite, bool create);
|
||||
Variant *createLvalPtr(CStrRef key, bool forWrite);
|
||||
Variant *getLvalPtr(CStrRef key, bool forWrite);
|
||||
|
||||
Variant &lvalAt();
|
||||
|
||||
|
||||
@@ -1650,7 +1650,7 @@ static Array const_data;
|
||||
|
||||
Variant f_fb_const_fetch(CVarRef key) {
|
||||
String k = key.toString();
|
||||
Variant *ret = const_data.lvalPtr(k, false, false);
|
||||
Variant *ret = const_data.getLvalPtr(k, false);
|
||||
if (ret) return *ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -267,8 +267,8 @@ void Instance::propImpl(TypedValue*& retval, TypedValue& tvRef,
|
||||
if (o_properties.get() == nullptr) {
|
||||
initDynProps();
|
||||
}
|
||||
o_properties.get()->lvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&retval), false, true);
|
||||
o_properties.get()->createLvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&retval), false);
|
||||
} else {
|
||||
retval = (TypedValue*)&init_null_variant;
|
||||
}
|
||||
@@ -433,8 +433,8 @@ TypedValue* Instance::setOpProp(TypedValue& tvRef, Class* ctx,
|
||||
if (o_properties.get() == nullptr) {
|
||||
initDynProps();
|
||||
}
|
||||
o_properties.get()->lvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&propVal), false, true);
|
||||
o_properties.get()->createLvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&propVal), false);
|
||||
// don't write propVal->_count because it holds data
|
||||
// owned by the HphpArray
|
||||
propVal->m_type = KindOfNull;
|
||||
@@ -448,8 +448,8 @@ TypedValue* Instance::setOpProp(TypedValue& tvRef, Class* ctx,
|
||||
if (o_properties.get() == nullptr) {
|
||||
initDynProps();
|
||||
}
|
||||
o_properties.get()->lvalPtr(*(const String*)&key, *(Variant**)(&propVal),
|
||||
false, true);
|
||||
o_properties.get()->createLvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&propVal), false);
|
||||
// don't write propVal->_count because it holds data
|
||||
// owned by the HphpArray
|
||||
propVal->m_data.num = tvResult.m_data.num;
|
||||
@@ -506,8 +506,8 @@ void Instance::incDecPropImpl(TypedValue& tvRef, Class* ctx,
|
||||
if (o_properties.get() == nullptr) {
|
||||
initDynProps();
|
||||
}
|
||||
o_properties.get()->lvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&propVal), false, true);
|
||||
o_properties.get()->createLvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&propVal), false);
|
||||
// don't write propVal->_count because it holds data
|
||||
// owned by the HphpArray
|
||||
propVal->m_type = KindOfNull;
|
||||
@@ -521,8 +521,8 @@ void Instance::incDecPropImpl(TypedValue& tvRef, Class* ctx,
|
||||
if (o_properties.get() == nullptr) {
|
||||
initDynProps();
|
||||
}
|
||||
o_properties.get()->lvalPtr(*(const String*)&key, *(Variant**)(&propVal),
|
||||
false, true);
|
||||
o_properties.get()->createLvalPtr(*(const String*)&key,
|
||||
*(Variant**)(&propVal), false);
|
||||
// don't write propVal->_count because it holds data
|
||||
// owned by the HphpArray
|
||||
propVal->m_data.num = tvResult.m_data.num;
|
||||
@@ -792,7 +792,7 @@ void Instance::cloneSet(ObjectData* clone) {
|
||||
TypedValue *val = props->nvGet(strKey);
|
||||
TypedValue *retval;
|
||||
auto cloneProps = iclone->o_properties.get();
|
||||
cloneProps->lvalPtr(strKey, *(Variant**)&retval, false, true);
|
||||
cloneProps->createLvalPtr(strKey, *(Variant**)&retval, false);
|
||||
tvDupFlattenVars(val, retval, cloneProps);
|
||||
iter = o_properties.get()->iter_advance(iter);
|
||||
decRefStr(strKey);
|
||||
|
||||
@@ -67,7 +67,6 @@ public: // ArrayData implementation
|
||||
using ArrayData::get;
|
||||
using ArrayData::lval;
|
||||
using ArrayData::lvalNew;
|
||||
using ArrayData::lvalPtr;
|
||||
using ArrayData::set;
|
||||
using ArrayData::setRef;
|
||||
using ArrayData::add;
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário