Remove ArrayData::getIndex virtual methods.

They aren't used anymore, except to implement isVectorData(),
which we can make pure-virtual and implement more efficiently
in each subclass of ArrayData.
Esse commit está contido em:
Edwin Smith
2013-06-10 11:12:14 -07:00
commit de sgolemon
commit 51967b2c12
11 arquivos alterados com 33 adições e 86 exclusões
-10
Ver Arquivo
@@ -137,16 +137,6 @@ Object ArrayData::toObject() const {
return Instance::FromArray(const_cast<ArrayData *>(this));
}
bool ArrayData::isVectorData() const {
const auto n = size();
for (ssize_t i = 0; i < n; i++) {
if (getIndex(i) != i) {
return false;
}
}
return true;
}
int ArrayData::compare(const ArrayData *v2) const {
assert(v2);
+1 -10
Ver Arquivo
@@ -183,7 +183,7 @@ public:
* Returns whether or not this array contains "vector-like" data.
* I.e. all the keys are contiguous increasing integers.
*/
virtual bool isVectorData() const;
virtual bool isVectorData() const = 0;
/**
* Whether or not this array has a referenced Variant or Object appearing
@@ -232,13 +232,6 @@ public:
virtual TypedValue* nvGetCell(int64_t ki) const;
virtual TypedValue* nvGetCell(const StringData* k) const;
/**
* Get the numeric index for a key. Only these need to be
* in ArrayData.
*/
virtual ssize_t getIndex(int64_t k) const = 0;
virtual ssize_t getIndex(const StringData* k) const = 0;
/**
* Getting l-value (that Variant pointer) at specified key. Return NULL if
* escalation is not needed, or an escalated array data.
@@ -307,8 +300,6 @@ public:
bool exists(CVarRef k) const;
CVarRef get(CStrRef k, bool error = false) const;
CVarRef get(CVarRef k, bool error = false) const;
ssize_t getIndex(CStrRef k) const;
ssize_t getIndex(CVarRef k) 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);
-12
Ver Arquivo
@@ -63,18 +63,6 @@ inline CVarRef ArrayData::get(CVarRef k, bool error) const {
get(getStringKey(tvk), error);
}
inline ssize_t ArrayData::getIndex(CStrRef k) const {
assert(IsValidKey(k));
return getIndex(k.get());
}
inline ssize_t ArrayData::getIndex(CVarRef k) const {
assert(IsValidKey(k));
TypedValueAccessor tvk = k.getTypedAccessor();
return isIntKey(tvk) ? getIndex(getIntKey(tvk)) :
getIndex(getStringKey(tvk));
}
inline ArrayData* ArrayData::lval(CStrRef k, Variant *&ret, bool copy,
bool checkExist) {
assert(IsValidKey(k));
-8
Ver Arquivo
@@ -593,14 +593,6 @@ CVarRef HphpArray::get(const StringData* key, bool error /* = false */) const {
return error ? getNotFound(key) : null_variant;
}
ssize_t HphpArray::getIndex(int64_t k) const {
return ssize_t(find(k));
}
ssize_t HphpArray::getIndex(const StringData* k) const {
return ssize_t(find(k, k->hash()));
}
//=============================================================================
// Append/insert/update.
-5
Ver Arquivo
@@ -81,7 +81,6 @@ public:
// from a CVarRef key to int64.
using ArrayData::exists;
using ArrayData::get;
using ArrayData::getIndex;
using ArrayData::lval;
using ArrayData::lvalNew;
using ArrayData::lvalPtr;
@@ -122,10 +121,6 @@ public:
CVarRef get(int64_t k, bool error=false) const FLATTEN;
CVarRef get(const StringData* k, bool error=false) const FLATTEN;
// implements ArrayData
ssize_t getIndex(int64_t k) const;
ssize_t getIndex(const StringData* k) const;
// implements ArrayData
ArrayData* lval(int64_t k, Variant*& ret, bool copy, bool checkExist=false);
ArrayData* lval(StringData* k, Variant*& ret, bool copy,
+4 -7
Ver Arquivo
@@ -230,7 +230,10 @@ const Variant& ArrayShell::getValueRef(ssize_t pos) const {
bool ArrayShell::isVectorData() const {
APILOG << "()";
return ArrayData::isVectorData();
for (ssize_t i = 0; i < m_size; ++i) {
if (Store::find(i, m_size) != toPos(i)) return false;
}
return true;
}
Variant ArrayShell::reset() {
@@ -340,12 +343,6 @@ TypedValue* ArrayShell::nvGetCellImpl(K k) const {
: nvGetNotFound(k);
}
template <class K>
ssize_t ArrayShell::getIndexImpl(K k) const {
APILOG << "(" << keystr(k) << ")";
return toInt64(find(k, m_size));
}
template <class K>
const Variant& ArrayShell::getImpl(K k, bool error) const {
APILOG << "(" << keystr(k) << ", " << error << ")";
-15
Ver Arquivo
@@ -451,21 +451,6 @@ public:
return nvGetCellImpl(k);
}
/**
* Get the numeric index for a key. Only these need to be
* in ArrayData.
*/
private:
template <class K> ssize_t getIndexImpl(K k) const;
public:
virtual ssize_t getIndex(int64_t k) const FOLLY_OVERRIDE {
return getIndexImpl(k);
}
virtual ssize_t getIndex(const StringData* k) const FOLLY_OVERRIDE {
return getIndexImpl(k);
}
private:
template <class K>
ArrayData *lvalImpl(K k, Variant *&ret, bool copy, bool checkExist);
+17 -2
Ver Arquivo
@@ -14,8 +14,8 @@
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/base/type_conversions.h"
#include "hphp/runtime/base/shared/shared_map.h"
#include "hphp/runtime/base/type_conversions.h"
#include "hphp/runtime/base/array/array_iterator.h"
#include "hphp/runtime/base/array/array_init.h"
#include "hphp/runtime/base/runtime_option.h"
@@ -68,12 +68,27 @@ ssize_t SharedMap::getIndex(int64_t k) const {
return m_map->indexOf(k);
}
bool SharedMap::isVectorData() const {
if (isVector()) return true;
const auto n = size();
for (ssize_t i = 0; i < n; i++) {
if (m_map->indexOf(i) != i) return false;
}
return true;
}
bool SharedMap::exists(const StringData* k) const {
return getIndex(k) != -1;
if (isVector()) return false;
return m_map->indexOf(k) != -1;
}
bool SharedMap::exists(int64_t k) const {
return getIndex(k) != -1;
if (isVector()) {
if (k < 0 || (size_t)k >= m_vec->m_size) return false;
return true;
}
return m_map->indexOf(k) != -1;
}
CVarRef SharedMap::get(const StringData* k, bool error /* = false */) const {
+6 -4
Ver Arquivo
@@ -47,7 +47,6 @@ public:
// from a CVarRef key to int64.
using ArrayData::exists;
using ArrayData::get;
using ArrayData::getIndex;
using ArrayData::lval;
using ArrayData::lvalNew;
using ArrayData::lvalPtr;
@@ -82,9 +81,6 @@ public:
CVarRef get(int64_t k, bool error = false) const;
CVarRef get(const StringData* k, bool error = false) const;
ssize_t getIndex(int64_t k) const;
ssize_t getIndex(const StringData* k) const;
virtual ArrayData *lval(int64_t k, Variant *&ret, bool copy,
bool checkExist = false);
virtual ArrayData *lval(StringData* k, Variant *&ret, bool copy,
@@ -120,6 +116,8 @@ public:
TypedValue* nvGetCell(int64_t ki) const;
TypedValue* nvGetCell(const StringData* k) const;
bool isVectorData() const;
/**
* Memory allocator methods.
*/
@@ -130,6 +128,10 @@ public:
ArrayData* loadElems(bool mapInit = false) const;
private:
ssize_t getIndex(int64_t k) const;
ssize_t getIndex(const StringData* k) const;
private:
bool m_isVector;
union {
+4 -9
Ver Arquivo
@@ -93,15 +93,6 @@ TypedValue* NameValueTableWrapper::nvGet(int64_t k) const {
return m_tab->lookup(String(k).get());
}
ssize_t NameValueTableWrapper::getIndex(int64_t k) const {
return getIndex(String(k));
}
ssize_t NameValueTableWrapper::getIndex(const StringData* k) const {
NameValueTable::Iterator iter(m_tab, k);
return iter.toInteger();
}
ArrayData* NameValueTableWrapper::lval(int64_t k, Variant*& ret, bool copy,
bool checkExist) {
return lval(String(k), ret, copy, checkExist);
@@ -315,6 +306,10 @@ void NameValueTableWrapper::uksort(CVarRef cmp_function) {}
void NameValueTableWrapper::usort(CVarRef cmp_function) {}
void NameValueTableWrapper::uasort(CVarRef cmp_function) {}
bool NameValueTableWrapper::isVectorData() const {
return false;
}
//////////////////////////////////////////////////////////////////////
}
+1 -4
Ver Arquivo
@@ -65,7 +65,6 @@ public: // ArrayData implementation
// from a CVarRef key to int64.
using ArrayData::exists;
using ArrayData::get;
using ArrayData::getIndex;
using ArrayData::lval;
using ArrayData::lvalNew;
using ArrayData::lvalPtr;
@@ -91,9 +90,6 @@ public: // ArrayData implementation
virtual TypedValue* nvGet(int64_t k) const;
virtual TypedValue* nvGet(const StringData* k) const;
virtual ssize_t getIndex(int64_t k) const;
virtual ssize_t getIndex(const StringData* k) const;
virtual ArrayData* lval(int64_t k, Variant*& ret, bool copy,
bool checkExist = false);
virtual ArrayData* lval(StringData* k, Variant*& ret,
@@ -134,6 +130,7 @@ public: // ArrayData implementation
virtual Variant each();
virtual bool validFullPos(const FullPos & fp) const;
virtual bool advanceFullPos(FullPos&);
virtual bool isVectorData() const;
virtual ArrayData* escalateForSort();
virtual void ksort(int sort_flags, bool ascending);