autoloading: change currently-loading array to be indexed by classNames

Mainly interested in the perflab here, as looping over all the values
 is certainly less efficient O(autoload-depth) as opposed to O(1).

 Also, gets rid of the last use of Array::valueExists

Reviewed By: @scannell

Differential Revision: D1137619
Esse commit está contido em:
Eugene Letuchy
2014-01-21 22:19:44 -08:00
commit de Sara Golemon
commit c724f89d7b
3 arquivos alterados com 14 adições e 22 exclusões
+14 -10
Ver Arquivo
@@ -1191,18 +1191,22 @@ bool AutoloadHandler::invokeHandler(const String& className,
if (res != Failure) return res == Success;
}
}
// If we end up in a recursive autoload loop where we try to load the same
// class twice, just fail the load to mimic PHP as many frameworks rely on it
// unless we are forcing a restart (due to spl_autoload_call) in which case
// it's allowed to re-enter. This means we can still overflow the stack if
// there is a loop when using spl_autoload_call directly but this is parity.
if (!forceSplStack && m_loading.valueExists(className)) {
return false;
// If we end up in a recursive autoload loop where we try to load the
// same class twice, just fail the load to mimic PHP as many frameworks
// rely on it unless we are forcing a restart (due to spl_autoload_call)
// in which case autoload is allowed to be reentrant.
if (!forceSplStack) {
if (m_loading.exists(className)) { return false; }
m_loading.add(className, className);
} else {
// We can still overflow the stack if there is a loop when using
// spl_autoload_call directly, but this behavior matches the reference
// implementation.
m_loading.append(className);
}
m_loading.append(className);
// The below code can throw so make sure we clean up the state from this load
// Make sure state is cleaned up from this load; autoloading of arbitrary
// code below can throw
SCOPE_EXIT {
String l_className = m_loading.pop();
assert(l_className == className);
-11
Ver Arquivo
@@ -593,17 +593,6 @@ void Array::add(CVarRef key, CVarRef v, bool isKey /* = false */) {
///////////////////////////////////////////////////////////////////////////////
// membership functions
bool Array::valueExists(CVarRef search_value,
bool strict /* = false */) const {
for (ArrayIter iter(*this); iter; ++iter) {
if ((strict && HPHP::same(iter.secondRef(), search_value)) ||
(!strict && HPHP::equal(iter.secondRef(), search_value))) {
return true;
}
}
return false;
}
Array Array::values() const {
PackedArrayInit ai(size());
for (ArrayIter iter(*this); iter; ++iter) {
-1
Ver Arquivo
@@ -135,7 +135,6 @@ public:
bool isNull() const {
return m_px == nullptr;
}
bool valueExists(CVarRef search_value, bool strict = false) const;
Array values() const;
/*