Rewrite get using nvGet()
Profile data shows much heavier use of ArrayData::nvGet(), nvGetCell(), and exists(), than get(). So rewrite get() using nvGet().
Esse commit está contido em:
@@ -479,6 +479,13 @@ bool ArrayData::hasInternalReference(PointerSet &vars,
|
||||
return false;
|
||||
}
|
||||
|
||||
CVarRef ArrayData::get(CVarRef k, bool error) const {
|
||||
assert(IsValidKey(k));
|
||||
auto const cell = k.asCell();
|
||||
return isIntKey(cell) ? get(getIntKey(cell), error)
|
||||
: get(getStringKey(cell), error);
|
||||
}
|
||||
|
||||
// nvGet has to search twice when using the ArrayData api so as not to
|
||||
// conflate no-key with have-key && value == null_varaint. Subclasses
|
||||
// can easily do this with one key search.
|
||||
@@ -522,13 +529,23 @@ CVarRef ArrayData::getNotFound(int64_t k) {
|
||||
return null_variant;
|
||||
}
|
||||
|
||||
CVarRef ArrayData::getNotFound(CStrRef k) {
|
||||
raise_notice("Undefined index: %s", k.data());
|
||||
CVarRef ArrayData::getNotFound(const StringData* k) {
|
||||
raise_notice("Undefined index: %s", k->data());
|
||||
return null_variant;
|
||||
}
|
||||
|
||||
CVarRef ArrayData::getNotFound(const StringData* k) {
|
||||
raise_notice("Undefined index: %s", k->data());
|
||||
CVarRef ArrayData::getNotFound(int64_t k, bool error) const {
|
||||
return error && m_kind != ArrayKind::kNameValueTableWrapper ? getNotFound(k) :
|
||||
null_variant;
|
||||
}
|
||||
|
||||
CVarRef ArrayData::getNotFound(const StringData* k, bool error) const {
|
||||
return error && m_kind != ArrayKind::kNameValueTableWrapper ? getNotFound(k) :
|
||||
null_variant;
|
||||
}
|
||||
|
||||
CVarRef ArrayData::getNotFound(CStrRef k) {
|
||||
raise_notice("Undefined index: %s", k.data());
|
||||
return null_variant;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,12 +210,6 @@ public:
|
||||
virtual bool exists(int64_t k) const = 0;
|
||||
virtual bool exists(const StringData* k) const = 0;
|
||||
|
||||
/**
|
||||
* Getting value at specified key.
|
||||
*/
|
||||
virtual CVarRef get(int64_t k, bool error = false) const = 0;
|
||||
virtual CVarRef get(const StringData* k, bool error = false) const = 0;
|
||||
|
||||
/**
|
||||
* Interface for VM helpers. ArrayData implements generic versions
|
||||
* using the other ArrayData api; subclasses may do better.
|
||||
@@ -293,6 +287,8 @@ public:
|
||||
*/
|
||||
bool exists(CStrRef k) const;
|
||||
bool exists(CVarRef k) const;
|
||||
CVarRef get(int64_t k, bool error = false) const;
|
||||
CVarRef get(const StringData* k, bool error = false) const;
|
||||
CVarRef get(CStrRef k, bool error = false) const;
|
||||
CVarRef get(CVarRef k, bool error = false) const;
|
||||
ArrayData *lval(CStrRef k, Variant *&ret, bool copy, bool checkExist=false);
|
||||
@@ -472,6 +468,8 @@ public:
|
||||
// error-handling helpers
|
||||
static CVarRef getNotFound(int64_t k);
|
||||
static CVarRef getNotFound(const StringData* k);
|
||||
CVarRef getNotFound(int64_t k, bool error) const;
|
||||
CVarRef getNotFound(const StringData* k, bool error) const;
|
||||
static CVarRef getNotFound(CStrRef k);
|
||||
static CVarRef getNotFound(CVarRef k);
|
||||
static TypedValue* nvGetNotFound(int64_t k);
|
||||
|
||||
@@ -56,11 +56,14 @@ inline CVarRef ArrayData::get(CStrRef k, bool error) const {
|
||||
return get(k.get(), error);
|
||||
}
|
||||
|
||||
inline CVarRef ArrayData::get(CVarRef k, bool error) const {
|
||||
assert(IsValidKey(k));
|
||||
auto const cell = k.asCell();
|
||||
return isIntKey(cell) ? get(getIntKey(cell), error)
|
||||
: get(getStringKey(cell), error);
|
||||
inline CVarRef ArrayData::get(int64_t k, bool error) const {
|
||||
auto tv = nvGet(k);
|
||||
return tv ? tvAsCVarRef(tv) : getNotFound(k, error);
|
||||
}
|
||||
|
||||
inline CVarRef ArrayData::get(const StringData* k, bool error) const {
|
||||
auto tv = nvGet(k);
|
||||
return tv ? tvAsCVarRef(tv) : getNotFound(k, error);
|
||||
}
|
||||
|
||||
inline ArrayData* ArrayData::lval(CStrRef k, Variant *&ret, bool copy,
|
||||
|
||||
@@ -571,24 +571,6 @@ bool HphpArray::exists(const StringData* k) const {
|
||||
return pos != ssize_t(ElmIndEmpty);
|
||||
}
|
||||
|
||||
CVarRef HphpArray::get(int64_t k, bool error /* = false */) const {
|
||||
ElmInd pos = find(k);
|
||||
if (pos != ElmIndEmpty) {
|
||||
Elm* e = &m_data[pos];
|
||||
return tvAsCVarRef(&e->data);
|
||||
}
|
||||
return error ? getNotFound(k) : null_variant;
|
||||
}
|
||||
|
||||
CVarRef HphpArray::get(const StringData* key, bool error /* = false */) const {
|
||||
ElmInd pos = find(key, key->hash());
|
||||
if (pos != ElmIndEmpty) {
|
||||
Elm* e = &m_data[pos];
|
||||
return tvAsCVarRef(&e->data);
|
||||
}
|
||||
return error ? getNotFound(key) : null_variant;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// Append/insert/update.
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ public:
|
||||
// are visible in this class, to avoid triggering implicit conversions
|
||||
// from a CVarRef key to int64.
|
||||
using ArrayData::exists;
|
||||
using ArrayData::get;
|
||||
using ArrayData::lval;
|
||||
using ArrayData::lvalNew;
|
||||
using ArrayData::createLvalPtr;
|
||||
@@ -118,10 +117,6 @@ public:
|
||||
bool exists(int64_t k) const;
|
||||
bool exists(const StringData* k) const;
|
||||
|
||||
// implements ArrayData
|
||||
CVarRef get(int64_t k, bool error=false) const FLATTEN;
|
||||
CVarRef get(const StringData* k, bool error=false) const FLATTEN;
|
||||
|
||||
// implements ArrayData
|
||||
ArrayData* lval(int64_t k, Variant*& ret, bool copy, bool checkExist=false);
|
||||
ArrayData* lval(StringData* k, Variant*& ret, bool copy,
|
||||
|
||||
@@ -361,16 +361,6 @@ TypedValue* PolicyArray::nvGetCellImpl(K k) const {
|
||||
// return toInt64(find(k, m_size));
|
||||
// }
|
||||
|
||||
template <class K>
|
||||
const Variant& PolicyArray::getImpl(K k, bool error) const {
|
||||
APILOG << "(" << keystr(k) << ", " << error << ")";
|
||||
auto const pos = find(k, m_size);
|
||||
if (pos != PosType::invalid) {
|
||||
return val(pos);
|
||||
}
|
||||
return error ? getNotFound(k) : null_variant;
|
||||
}
|
||||
|
||||
template <class K>
|
||||
ArrayData *PolicyArray::lvalImpl(K k, Variant*& ret,
|
||||
bool copy, bool checkExist) {
|
||||
|
||||
@@ -405,26 +405,6 @@ public:
|
||||
return Store::find(k, m_size) < toPos(m_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting value at specified key.
|
||||
*/
|
||||
private:
|
||||
template <class K>
|
||||
const Variant& getImpl(K k, bool error) const;
|
||||
|
||||
public:
|
||||
// aalexandre: this API forces storage to store variants in the
|
||||
// TypedValue/Variant layout, thus disallowing e.g. implementations
|
||||
// that store type tags and values separately.
|
||||
virtual const Variant&
|
||||
get(int64_t k, bool error = false) const FOLLY_OVERRIDE {
|
||||
return getImpl(k, error);
|
||||
}
|
||||
virtual const Variant&
|
||||
get(const StringData* k, bool error = false) const FOLLY_OVERRIDE {
|
||||
return getImpl(k, error);
|
||||
}
|
||||
|
||||
private:
|
||||
template <class K> TypedValue* nvGetImpl(K k) const;
|
||||
|
||||
|
||||
@@ -91,22 +91,6 @@ bool SharedMap::exists(int64_t k) const {
|
||||
return m_map->indexOf(k) != -1;
|
||||
}
|
||||
|
||||
CVarRef SharedMap::get(const StringData* k, bool error /* = false */) const {
|
||||
int index = getIndex(k);
|
||||
if (index == -1) {
|
||||
return error ? getNotFound(k) : null_variant;
|
||||
}
|
||||
return getValueRef(index);
|
||||
}
|
||||
|
||||
CVarRef SharedMap::get(int64_t k, bool error /* = false */) const {
|
||||
int index = getIndex(k);
|
||||
if (index == -1) {
|
||||
return error ? getNotFound(k) : null_variant;
|
||||
}
|
||||
return getValueRef(index);
|
||||
}
|
||||
|
||||
/* if a2 is modified copy of a1 (i.e. != a1), then release a1 and return a2 */
|
||||
inline ArrayData* releaseIfCopied(ArrayData* a1, ArrayData* a2) {
|
||||
if (a1 != a2) a1->release();
|
||||
|
||||
@@ -46,7 +46,6 @@ public:
|
||||
// are visible in this class, to avoid triggering implicit conversions
|
||||
// from a CVarRef key to int64.
|
||||
using ArrayData::exists;
|
||||
using ArrayData::get;
|
||||
using ArrayData::lval;
|
||||
using ArrayData::lvalNew;
|
||||
using ArrayData::set;
|
||||
@@ -77,9 +76,6 @@ public:
|
||||
bool exists(int64_t k) const;
|
||||
bool exists(const StringData* k) const;
|
||||
|
||||
CVarRef get(int64_t k, bool error = false) const;
|
||||
CVarRef get(const StringData* k, bool error = false) const;
|
||||
|
||||
virtual ArrayData *lval(int64_t k, Variant *&ret, bool copy,
|
||||
bool checkExist = false);
|
||||
virtual ArrayData *lval(StringData* k, Variant *&ret, bool copy,
|
||||
|
||||
@@ -68,23 +68,6 @@ bool NameValueTableWrapper::idxExists(ssize_t idx) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
CVarRef NameValueTableWrapper::get(int64_t k, bool error) const {
|
||||
return get(String(k), error);
|
||||
}
|
||||
|
||||
CVarRef NameValueTableWrapper::get(const StringData* k, bool error) const {
|
||||
TypedValue* tv = m_tab->lookup(k);
|
||||
if (tv) {
|
||||
return tvAsCVarRef(tv);
|
||||
}
|
||||
// NOTE: ignoring error on these, as global_array_wrapper does so too,
|
||||
// but I'm not sure why.
|
||||
// if (error) {
|
||||
// raise_notice("Undefined index: %s", k->data());
|
||||
// }
|
||||
return null_variant;
|
||||
}
|
||||
|
||||
TypedValue* NameValueTableWrapper::nvGet(const StringData* k) const {
|
||||
return m_tab->lookup(k);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ public: // ArrayData implementation
|
||||
// are visible in this class, to avoid triggering implicit conversions
|
||||
// from a CVarRef key to int64.
|
||||
using ArrayData::exists;
|
||||
using ArrayData::get;
|
||||
using ArrayData::lval;
|
||||
using ArrayData::lvalNew;
|
||||
using ArrayData::set;
|
||||
@@ -87,9 +86,6 @@ public: // ArrayData implementation
|
||||
virtual bool exists(const StringData* k) const;
|
||||
virtual bool idxExists(ssize_t idx) const;
|
||||
|
||||
virtual CVarRef get(int64_t k, bool error = false) const;
|
||||
virtual CVarRef get(const StringData* k, bool error = false) const;
|
||||
|
||||
virtual TypedValue* nvGet(int64_t k) const;
|
||||
virtual TypedValue* nvGet(const StringData* k) const;
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário