Delete all the non-variant Variant::same overloads

Step one.
Esse commit está contido em:
Jordan DeLong
2013-06-05 22:03:35 -07:00
commit de sgolemon
commit 2618ad0ef2
19 arquivos alterados com 131 adições e 121 exclusões
+66 -2
Ver Arquivo
@@ -19,7 +19,71 @@
#include "hphp/runtime/base/zend/zend_string.h"
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Variant
bool same(CVarRef v1, bool v2) {
return v1.isBoolean() && v2 == v1.getBoolean();
}
bool same(CVarRef v1, int64_t v2) {
auto const acc = v1.getTypedAccessor();
switch (acc->m_type) {
case KindOfInt64:
return v2 == acc->m_data.num;
default:
break;
}
return false;
}
bool same(CVarRef v1, double d) {
return v1.isDouble() && v1.getDouble() == d;
}
bool same(CVarRef v1, const StringData* v2) {
bool null1 = v1.isNull();
bool null2 = (v2 == nullptr);
if (null1 && null2) return true;
if (null1 || null2) return false;
if (!v1.isString()) return false;
auto const sdata = v1.getStringData();
return sdata == v2 || v2->same(sdata);
}
// TODO(#2298051) litstr must die
bool same(CVarRef v1, litstr v2) {
StackStringData sd2(v2);
return same(v1, &sd2);
}
bool same(CVarRef v1, CStrRef v2) {
const StringData* sd = v2.get();
return same(v1, sd);
}
bool same(CVarRef v1, CArrRef v2) {
bool null1 = v1.isNull();
bool null2 = v2.isNull();
if (null1 && null2) return true;
if (null1 || null2) return false;
if (!v1.isArray()) return false;
auto const ad = v1.getArrayData();
return v2->equal(ad, true);
}
bool same(CVarRef v1, CObjRef v2) {
bool null1 = v1.isNull();
bool null2 = v2.isNull();
if (null1 && null2) return true;
if (null1 || null2) return false;
if (!v1.isObject()) return false;
auto const od = v1.getObjectData();
return od == v2.get();
}
//////////////////////////////////////////////////////////////////////
bool less_or_equal(CVarRef v1, CVarRef v2) {
// To be PHP-compatible, when comparing two arrays or two objects we
@@ -165,5 +229,5 @@ bool more(int64_t v1, const StringData *v2) {
}
}
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
}
+10 -10
Ver Arquivo
@@ -25,16 +25,16 @@ namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
// Variant
inline bool same(CVarRef v1, bool v2) { return v1.same(v2);}
inline bool same(CVarRef v1, int v2) { return v1.same(v2);}
inline bool same(CVarRef v1, int64_t v2) { return v1.same(v2);}
inline bool same(CVarRef v1, double v2) { return v1.same(v2);}
inline bool same(CVarRef v1, const StringData *v2) { return v1.same(v2);}
inline bool same(CVarRef v1, CStrRef v2) { return v1.same(v2);}
inline bool same(CVarRef v1, litstr v2) { return v1.same(v2);}
inline bool same(CVarRef v1, CArrRef v2) { return v1.same(v2);}
inline bool same(CVarRef v1, CObjRef v2) { return v1.same(v2);}
inline bool same(CVarRef v1, CVarRef v2) { return v1.same(v2);}
bool same(CVarRef v1, bool v2);
bool same(CVarRef v1, int64_t v2);
inline bool same(CVarRef v1, int v2) { return same(v1, (int64_t)v2); }
bool same(CVarRef v1, double v2);
bool same(CVarRef v1, const StringData* v2);
bool same(CVarRef v1, CStrRef v2);
bool same(CVarRef v1, litstr v2);
bool same(CVarRef v1, CArrRef v2);
bool same(CVarRef v1, CObjRef v2);
inline bool same(CVarRef v1, CVarRef v2) { return v1.same(v2); }
inline bool equal(CVarRef v1, bool v2) { return v1.equal(v2);}
inline bool equal(CVarRef v1, int v2) { return v1.equal(v2);}
+1 -1
Ver Arquivo
@@ -38,7 +38,7 @@ SourceRootInfo::SourceRootInfo(const char *host)
Variant r = preg_match(String(RuntimeOption::SandboxPattern.c_str(),
RuntimeOption::SandboxPattern.size(),
AttachLiteral), host, matches);
if (!r.same(1)) {
if (!same(r, 1)) {
m_sandboxCond = SandboxOff;
return;
}
+1 -1
Ver Arquivo
@@ -305,7 +305,7 @@ bool VirtualHost::rewriteURL(CStrRef host, String &url, bool &qsa,
}
Variant ret = preg_match(String(it->pattern.c_str(), it->pattern.size(),
AttachLiteral), subject);
if (!ret.same(it->negate ? 0 : 1)) {
if (!same(ret, it->negate ? 0 : 1)) {
passed = false;
break;
}
-56
Ver Arquivo
@@ -1545,62 +1545,6 @@ Variant::operator Object() const {
///////////////////////////////////////////////////////////////////////////////
// comparisons
bool Variant::same(bool v2) const {
return isBoolean() && HPHP::equal(v2, getBoolean());
}
bool Variant::same(int v2) const {
return same((int64_t)v2);
}
bool Variant::same(int64_t v2) const {
TypedValueAccessor acc = getTypedAccessor();
switch (GetAccessorType(acc)) {
case KindOfInt64:
return HPHP::equal(v2, GetInt64(acc));
default:
break;
}
return false;
}
bool Variant::same(double v2) const {
return isDouble() && HPHP::equal(v2, getDouble());
}
bool Variant::same(litstr v2) const {
StackStringData sd2(v2);
return same(&sd2);
}
bool Variant::same(const StringData *v2) const {
bool null1 = isNull();
bool null2 = (v2 == nullptr);
if (null1 && null2) return true;
if (null1 || null2) return false;
return isString() && HPHP::same(getStringData(), v2);
}
bool Variant::same(CStrRef v2) const {
return same(v2.get());
}
bool Variant::same(CArrRef v2) const {
bool null1 = isNull();
bool null2 = v2.isNull();
if (null1 && null2) return true;
if (null1 || null2) return false;
return is(KindOfArray) && Array(getArrayData()).same(v2);
}
bool Variant::same(CObjRef v2) const {
bool null1 = isNull();
bool null2 = v2.isNull();
if (null1 && null2) return true;
if (null1 || null2) return false;
return is(KindOfObject) && getObjectData() == v2.get();
}
bool Variant::same(CVarRef v2) const {
bool null1 = isNull();
bool null2 = v2.isNull();
+9 -9
Ver Arquivo
@@ -697,15 +697,15 @@ class Variant : private TypedValue {
/**
* Comparisons
*/
bool same(bool v2) const;
bool same(int v2) const;
bool same(int64_t v2) const;
bool same(double v2) const;
bool same(litstr v2) const;
bool same(const StringData *v2) const;
bool same(CStrRef v2) const;
bool same(CArrRef v2) const;
bool same(CObjRef v2) const;
bool same(bool v2) const = delete;
bool same(int v2) const = delete;
bool same(int64_t v2) const = delete;
bool same(double v2) const = delete;
bool same(litstr v2) const = delete;
bool same(const StringData *v2) const = delete;
bool same(CStrRef v2) const = delete;
bool same(CArrRef v2) const = delete;
bool same(CObjRef v2) const = delete;
bool same(CVarRef v2) const;
bool equal(bool v2) const;
+1 -1
Ver Arquivo
@@ -380,7 +380,7 @@ void VariableSerializer::write(CObjRef v) {
assert(!v->isCollection());
Variant ret = v->o_invoke_few_args(s_jsonSerialize, 0);
// for non objects or when $this is returned
if (!ret.isObject() || (ret.isObject() && !ret.same(v))) {
if (!ret.isObject() || (ret.isObject() && !same(ret, v))) {
write(ret);
return;
}
+1 -1
Ver Arquivo
@@ -76,7 +76,7 @@ bool VariableUnserializer::isWhitelistedClass(CStrRef cls_name) const {
if (!m_classWhiteList.isNull() && !m_classWhiteList.empty()) {
for (ArrayIter iter(m_classWhiteList); iter; ++iter) {
CVarRef value(iter.secondRef());
if (f_is_subclass_of(cls_name, value) || value.same(cls_name)) {
if (f_is_subclass_of(cls_name, value) || same(value, cls_name)) {
return true;
}
}
+6 -5
Ver Arquivo
@@ -23,6 +23,7 @@
#include "hphp/runtime/base/complex_types.h"
#include "hphp/runtime/base/runtime_error.h"
#include "hphp/runtime/base/array/array_iterator.h"
#include "hphp/runtime/base/comparisons.h"
namespace HPHP {
@@ -311,7 +312,7 @@ static String intl_convert_str_utf16_to_utf8(CStrRef utf16_str,
static Variant collator_convert_string_to_number(CVarRef str) {
Variant num = collator_convert_string_to_number_if_possible(str);
if (num.same(false)) {
if (same(num, false)) {
/* String wasn't converted => return zero. */
return 0;
}
@@ -390,7 +391,7 @@ static Variant collator_normalize_sort_argument(CVarRef arg) {
if (!arg.isString()) return arg;
Variant n_arg = collator_convert_string_to_number_if_possible(arg);
if (n_arg.same(false)) {
if (same(n_arg, false)) {
/* Conversion to number failed. */
UErrorCode status;
n_arg = intl_convert_str_utf16_to_utf8(arg, &status);
@@ -416,10 +417,10 @@ static int collator_regular_compare_function(CVarRef v1, CVarRef v2,
* then use ICU-compare. Otherwise PHP-compare. */
if (str1.isString() && str2.isString()) {
num1 = collator_convert_string_to_number_if_possible(str1);
if (!num1.same(false)) {
if (!same(num1, false)) {
num2 = collator_convert_string_to_number_if_possible(str2);
}
if (num1.same(false) || num2.same(false)) {
if (same(num1, false) || same(num2, false)) {
assert(data);
int ret = ucol_strcoll((const UCollator *)data,
(UChar*)(str1.toString().data()),
@@ -432,7 +433,7 @@ static int collator_regular_compare_function(CVarRef v1, CVarRef v2,
/* num1 is set if str1 and str2 are strings. */
if (!num1.isNull()) {
if (num1.same(false)) {
if (same(num1, false)) {
/* str1 is string but not numeric string just convert it to utf8. */
UErrorCode status;
norm1 = intl_convert_str_utf16_to_utf8(str1, &status);
+2 -1
Ver Arquivo
@@ -23,6 +23,7 @@
#include "hphp/runtime/base/class_info.h"
#include "hphp/runtime/base/stat_cache.h"
#include "hphp/runtime/vm/jit/translator-inline.h"
#include "hphp/runtime/base/comparisons.h"
namespace HPHP { namespace Eval {
///////////////////////////////////////////////////////////////////////////////
@@ -860,7 +861,7 @@ bool BreakPointInfo::Match(const char *haystack, int haystack_len,
AttachLiteral),
String(haystack, haystack_len, AttachLiteral),
matches);
return r.same(1);
return HPHP::same(r, 1);
}
bool BreakPointInfo::checkExceptionOrError(CVarRef e) {
+16 -16
Ver Arquivo
@@ -242,14 +242,14 @@ static const StaticString s_days("days");
Variant c_DateInterval::t___get(Variant member) {
if (member.isString()) {
if (member.same(s_y)) return m_di->getYears();
if (member.same(s_m)) return m_di->getMonths();
if (member.same(s_d)) return m_di->getDays();
if (member.same(s_h)) return m_di->getHours();
if (member.same(s_i)) return m_di->getMinutes();
if (member.same(s_s)) return m_di->getSeconds();
if (member.same(s_invert)) return m_di->isInverted();
if (member.same(s_days)) {
if (same(member, s_y)) return m_di->getYears();
if (same(member, s_m)) return m_di->getMonths();
if (same(member, s_d)) return m_di->getDays();
if (same(member, s_h)) return m_di->getHours();
if (same(member, s_i)) return m_di->getMinutes();
if (same(member, s_s)) return m_di->getSeconds();
if (same(member, s_invert)) return m_di->isInverted();
if (same(member, s_days)) {
if (m_di->haveTotalDays()) {
return m_di->getTotalDays();
} else {
@@ -265,35 +265,35 @@ Variant c_DateInterval::t___get(Variant member) {
Variant c_DateInterval::t___set(Variant member, Variant value) {
if (member.isString()) {
if (member.same(s_y)) {
if (same(member, s_y)) {
m_di->setYears(value.toInt64());
return uninit_null();
}
if (member.same(s_m)) {
if (same(member, s_m)) {
m_di->setMonths(value.toInt64());
return uninit_null();
}
if (member.same(s_d)) {
if (same(member, s_d)) {
m_di->setDays(value.toInt64());
return uninit_null();
}
if (member.same(s_h)) {
if (same(member, s_h)) {
m_di->setHours(value.toInt64());
return uninit_null();
}
if (member.same(s_i)) {
if (same(member, s_i)) {
m_di->setMinutes(value.toInt64());
return uninit_null();
}
if (member.same(s_s)) {
if (same(member, s_s)) {
m_di->setSeconds(value.toInt64());
return uninit_null();
}
if (member.same(s_invert)) {
if (same(member, s_invert)) {
m_di->setInverted(value.toBoolean());
return uninit_null();
}
if (member.same(s_days)) {
if (same(member, s_days)) {
m_di->setTotalDays(value.toInt64());
return uninit_null();
}
+1 -1
Ver Arquivo
@@ -517,7 +517,7 @@ Variant c_DebuggerClient::t_processcmd(CVarRef cmdName, CVarRef args) {
if (cmd == NULL) {
break;
}
if (cmdName.same(cmd)) {
if (same(cmdName, cmd)) {
allowed = true;
break;
}
+6 -6
Ver Arquivo
@@ -1620,7 +1620,7 @@ Variant f_iconv_mime_encode(CStrRef field_name, CStrRef field_value,
Variant f_iconv_mime_decode(CStrRef encoded_string, int mode /* = 0 */,
CStrRef charset /* = null_string */) {
Variant encoded = check_charset(charset);
if (encoded.same(false)) return false;
if (same(encoded, false)) return false;
String enc = encoded.toString();
StringBuffer retval;
php_iconv_err_t err =
@@ -1638,7 +1638,7 @@ Variant f_iconv_mime_decode_headers(CStrRef encoded_headers,
int mode /* = 0 */,
CStrRef charset /* = null_string */) {
Variant encoded = check_charset(charset);
if (encoded.same(false)) return false;
if (same(encoded, false)) return false;
String enc = encoded.toString();
Array ret;
php_iconv_err_t err = PHP_ICONV_ERR_SUCCESS;
@@ -1757,7 +1757,7 @@ Variant f_iconv(CStrRef in_charset, CStrRef out_charset, CStrRef str) {
Variant f_iconv_strlen(CStrRef str, CStrRef charset /* = null_string */) {
Variant encoded = check_charset(charset);
if (encoded.same(false)) return false;
if (same(encoded, false)) return false;
String enc = encoded.toString();
unsigned int retval;
php_iconv_err_t err = _php_iconv_strlen(&retval, str.data(), str.size(),
@@ -1780,7 +1780,7 @@ Variant f_iconv_strpos(CStrRef haystack, CStrRef needle, int offset /* = 0 */,
}
Variant encoded = check_charset(charset);
if (encoded.same(false)) return false;
if (same(encoded, false)) return false;
String enc = encoded.toString();
unsigned int retval;
php_iconv_err_t err =
@@ -1800,7 +1800,7 @@ Variant f_iconv_strrpos(CStrRef haystack, CStrRef needle,
}
Variant encoded = check_charset(charset);
if (encoded.same(false)) return false;
if (same(encoded, false)) return false;
String enc = encoded.toString();
unsigned int retval;
php_iconv_err_t err =
@@ -1816,7 +1816,7 @@ Variant f_iconv_strrpos(CStrRef haystack, CStrRef needle,
Variant f_iconv_substr(CStrRef str, int offset, int length /* = INT_MAX */,
CStrRef charset /* = null_string */) {
Variant encoded = check_charset(charset);
if (encoded.same(false)) return false;
if (same(encoded, false)) return false;
String enc = encoded.toString();
StringBuffer retval;
php_iconv_err_t err = _php_iconv_substr(retval, str.data(), str.size(),
+1 -1
Ver Arquivo
@@ -3118,7 +3118,7 @@ Variant c_PDOStatement::t_key() {
Variant c_PDOStatement::t_next() {
m_row = t_fetch(PDO_FETCH_USE_DEFAULT);
if (m_row.same(false)) {
if (same(m_row, false)) {
m_rowIndex = -1;
} else {
++m_rowIndex;
+2 -2
Ver Arquivo
@@ -272,7 +272,7 @@ Variant f_iterator_to_array(CVarRef obj, bool use_keys /* = true */) {
bool f_spl_autoload_register(CVarRef autoload_function /* = null_variant */,
bool throws /* = true */,
bool prepend /* = false */) {
if (autoload_function.same(s_spl_autoload_call)) {
if (same(autoload_function, s_spl_autoload_call)) {
if (throws) {
throw_spl_exception("Function spl_autoload_call()"
"cannot be registered");
@@ -289,7 +289,7 @@ bool f_spl_autoload_register(CVarRef autoload_function /* = null_variant */,
}
bool f_spl_autoload_unregister(CVarRef autoload_function) {
if (autoload_function.same(s_spl_autoload_call)) {
if (same(autoload_function, s_spl_autoload_call)) {
AutoloadHandler::s_instance->removeAllHandlers();
} else {
AutoloadHandler::s_instance->removeHandler(autoload_function);
+1 -1
Ver Arquivo
@@ -667,7 +667,7 @@ void _xml_unparsedEntityDeclHandler(void *userData,
}
static void xml_set_handler(Variant * handler, CVarRef data) {
if (data.same(false) || data.isString() ||
if (same(data, false) || data.isString() ||
(data.isArray() && data.getArrayData()->size() == 2 &&
(data[0].isString() || data[0].isObject()) &&
data[1].isString())) {
+4 -4
Ver Arquivo
@@ -493,8 +493,8 @@ bool TestExtMb::test_mb_strrchr() {
VS(f_strrchr(text, "\x9C"), "\x9C""Line 3");
// f_mb_strrchr behaves differently in different versions of
// libmbfl (https://github.com/facebook/hiphop-php/issues/68)
VERIFY(f_mb_strrchr(text, "\x9C").same(false) ||
f_mb_strrchr(text, "\x9C").same("Line 3"));
VERIFY(same(f_mb_strrchr(text, "\x9C"), false) ||
same(f_mb_strrchr(text, "\x9C"), String("Line 3")));
}
return Count(true);
}
@@ -567,8 +567,8 @@ bool TestExtMb::test_mb_substr_count() {
// different from substr_count
// f_mb_strrchr behaves differently in different versions of
// libmbfl (https://github.com/facebook/hiphop-php/issues/68)
VERIFY(f_mb_substr_count("gcdgcdgcd", "gcdgcd").same(2) ||
f_mb_substr_count("gcdgcdgcd", "gcdgcd").same(1));
VERIFY(same(f_mb_substr_count("gcdgcdgcd", "gcdgcd"), 2) ||
same(f_mb_substr_count("gcdgcdgcd", "gcdgcd"), 1));
return Count(true);
}
+1 -1
Ver Arquivo
@@ -42,7 +42,7 @@ bool TestExtMemcached::RunTests(const std::string &which) {
memc->t___construct(); \
memc->t_addserver(TEST_MEMCACHED_HOSTNAME, TEST_MEMCACHED_PORT); \
Variant memc_version = memc->t_getversion(); \
if (memc_version.same(false)) { \
if (same(memc_version, false)) { \
SKIP("No memcached running"); \
return Count(true); \
}
+2 -2
Ver Arquivo
@@ -752,7 +752,7 @@ bool TestExtString::test_strcmp() {
}
bool TestExtString::test_strncmp() {
VERIFY(f_strncmp("a", "ab", 1).same(0));
VERIFY(same(f_strncmp("a", "ab", 1), 0));
return Count(true);
}
@@ -797,7 +797,7 @@ bool TestExtString::test_strcasecmp() {
}
bool TestExtString::test_strncasecmp() {
VERIFY(f_strncasecmp("a", "Ab", 1).same(0));
VERIFY(same(f_strncasecmp("a", "Ab", 1), 0));
return Count(true);
}