From a73e674aeabe2766e499082d5ad3b8ae71e23c97 Mon Sep 17 00:00:00 2001 From: smith Date: Wed, 17 Apr 2013 16:26:46 -0700 Subject: [PATCH] Litstr must die, episode IV. Removed Array::remove(litstr). Grouped the other litstr overloads together and reimplemented each one in terms of the CStrRef overload. --- hphp/runtime/base/type_array.cpp | 49 +------ hphp/runtime/base/type_array.h | 22 ++-- hphp/runtime/base/type_string.h | 2 +- hphp/runtime/base/type_variant.h | 27 +++- hphp/runtime/eval/debugger/cmd/cmd_info.cpp | 121 +++++++++++------- hphp/runtime/eval/debugger/cmd/cmd_info.h | 2 +- .../eval/debugger/cmd/cmd_variable.cpp | 4 +- .../runtime/eval/debugger/debugger_client.cpp | 23 ++-- hphp/runtime/ext/ext_debugger.cpp | 25 ++-- hphp/runtime/ext/ext_function.cpp | 11 +- hphp/runtime/ext/ext_image.cpp | 2 +- hphp/runtime/ext/ext_openssl.cpp | 12 +- hphp/runtime/ext/ext_pdo.cpp | 2 +- hphp/runtime/ext/ext_simplexml.cpp | 5 +- hphp/runtime/ext/ext_soap.cpp | 6 +- hphp/runtime/ext/ext_xml.cpp | 26 ++-- hphp/runtime/ext/soap/encoding.cpp | 9 +- hphp/runtime/vm/bytecode.cpp | 6 +- hphp/test/test_cpp_base.cpp | 62 +++++---- hphp/test/test_ext_apc.cpp | 17 ++- hphp/test/test_ext_array.cpp | 10 +- hphp/test/test_ext_memcached.cpp | 45 +++++-- 22 files changed, 271 insertions(+), 217 deletions(-) diff --git a/hphp/runtime/base/type_array.cpp b/hphp/runtime/base/type_array.cpp index bf2d9ee0c..613fea592 100644 --- a/hphp/runtime/base/type_array.cpp +++ b/hphp/runtime/base/type_array.cpp @@ -435,15 +435,6 @@ CVarRef Array::rvalAtRef(double key, ACCESSPARAMS_IMPL) const { return null_variant; } -CVarRef Array::rvalAtRef(litstr key, ACCESSPARAMS_IMPL) const { - String strkey(key); - return rvalAtRef(strkey, flags); -} - -Variant Array::rvalAt(litstr key, ACCESSPARAMS_IMPL) const { - return Array::rvalAtRef(key, flags); -} - CVarRef Array::rvalAtRef(CStrRef key, ACCESSPARAMS_IMPL) const { if (m_px) { bool error = flags & AccessFlags::Error; @@ -531,15 +522,11 @@ Variant &Array::lvalAt() { return *ret; } -Variant &Array::lvalAt(litstr key, ACCESSPARAMS_IMPL) { - if (flags & AccessFlags::Key) return lvalAtImpl(String(key), flags); - return lvalAtImpl(String(key).toKey(), flags); -} - Variant &Array::lvalAt(CStrRef key, ACCESSPARAMS_IMPL) { if (flags & AccessFlags::Key) return lvalAtImpl(key, flags); return lvalAtImpl(key.toKey(), flags); } + Variant &Array::lvalAt(CVarRef key, ACCESSPARAMS_IMPL) { if (flags & AccessFlags::Key) return lvalAtImpl(key, flags); VarNR k(key.toKey()); @@ -593,11 +580,6 @@ CVarRef Array::set(int64_t key, CVarRef v) { return setImpl(key, v); } -CVarRef Array::set(litstr key, CVarRef v, bool isKey /* = false */) { - if (isKey) return setImpl(String(key), v); - return setImpl(String(key).toKey(), v); -} - CVarRef Array::set(CStrRef key, CVarRef v, bool isKey /* = false */) { if (isKey) return setImpl(key, v); return setImpl(key.toKey(), v); @@ -618,10 +600,7 @@ CVarRef Array::set(CVarRef key, CVarRef v, bool isKey /* = false */) { CVarRef Array::setRef(int64_t key, CVarRef v) { return setRefImpl(key, v); } -CVarRef Array::setRef(litstr key, CVarRef v, bool isKey /* = false */) { - if (isKey) return setRefImpl(String(key), v); - return setRefImpl(String(key).toKey(), v); -} + CVarRef Array::setRef(CStrRef key, CVarRef v, bool isKey /* = false */) { if (isKey) return setRefImpl(key, v); return setRefImpl(key.toKey(), v); @@ -642,14 +621,12 @@ CVarRef Array::setRef(CVarRef key, CVarRef v, bool isKey /* = false */) { CVarRef Array::add(int64_t key, CVarRef v) { return addImpl(key, v); } -CVarRef Array::add(litstr key, CVarRef v, bool isKey /* = false */) { - if (isKey) return addImpl(String(key), v); - return addImpl(String(key).toKey(), v); -} + CVarRef Array::add(CStrRef key, CVarRef v, bool isKey /* = false */) { if (isKey) return addImpl(key, v); return addImpl(key.toKey(), v); } + CVarRef Array::add(CVarRef key, CVarRef v, bool isKey /* = false */) { if (key.getRawType() == KindOfInt64) { return addImpl(key.getNumData(), v); @@ -662,11 +639,6 @@ CVarRef Array::add(CVarRef key, CVarRef v, bool isKey /* = false */) { return Variant::lvalBlackHole(); } -Variant &Array::addLval(litstr key, bool isKey /* = false */) { - if (isKey) return addLvalImpl(String(key)); - return addLvalImpl(String(key).toKey()); -} - Variant &Array::addLval(CStrRef key, bool isKey /* = false */) { if (isKey) return addLvalImpl(key); return addLvalImpl(key.toKey()); @@ -736,11 +708,6 @@ Array Array::values() const { return ai.create(); } -bool Array::exists(litstr key, bool isKey /* = false */) const { - String str(key); - return exists(str, isKey); -} - bool Array::exists(CStrRef key, bool isKey /* = false */) const { if (isKey) return existsImpl(key); return existsImpl(key.toKey()); @@ -762,14 +729,6 @@ bool Array::exists(CVarRef key, bool isKey /* = false */) const { return false; } -void Array::remove(litstr key, bool isString /* = false */) { - String k(key); - if (isString) { - removeImpl(k); - } else { - removeImpl(k.toKey()); - } -} void Array::remove(CStrRef key, bool isString /* = false */) { if (isString) { removeImpl(key); diff --git a/hphp/runtime/base/type_array.h b/hphp/runtime/base/type_array.h index 10d9ddd90..98218377b 100644 --- a/hphp/runtime/base/type_array.h +++ b/hphp/runtime/base/type_array.h @@ -256,7 +256,6 @@ class Array : protected SmartPtr { Variant rvalAt(int key, ACCESSPARAMS_DECL) const; Variant rvalAt(int64_t key, ACCESSPARAMS_DECL) const; Variant rvalAt(double key, ACCESSPARAMS_DECL) const; - Variant rvalAt(litstr key, ACCESSPARAMS_DECL) const; Variant rvalAt(CStrRef key, ACCESSPARAMS_DECL) const; Variant rvalAt(CVarRef key, ACCESSPARAMS_DECL) const; @@ -266,14 +265,12 @@ class Array : protected SmartPtr { CVarRef rvalAtRef(int key, ACCESSPARAMS_DECL) const; CVarRef rvalAtRef(int64_t key, ACCESSPARAMS_DECL) const; CVarRef rvalAtRef(double key, ACCESSPARAMS_DECL) const; - CVarRef rvalAtRef(litstr key, ACCESSPARAMS_DECL) const; CVarRef rvalAtRef(CVarRef key, ACCESSPARAMS_DECL) const; CVarRef rvalAtRef(CStrRef key, ACCESSPARAMS_DECL) const; const Variant operator[](int key) const; const Variant operator[](int64_t key) const; const Variant operator[](double key) const; - const Variant operator[](litstr key) const; const Variant operator[](CStrRef key) const; const Variant operator[](CVarRef key) const; @@ -308,7 +305,6 @@ class Array : protected SmartPtr { Variant &lvalAt(double key, ACCESSPARAMS_DECL) { return lvalAtImpl(ToKey(key), flags); } - Variant &lvalAt(litstr key, ACCESSPARAMS_DECL); Variant &lvalAt(CStrRef key, ACCESSPARAMS_DECL); Variant &lvalAt(CVarRef key, ACCESSPARAMS_DECL); @@ -326,7 +322,6 @@ class Array : protected SmartPtr { return set(ToKey(key), v); } - CVarRef set(litstr key, CVarRef v, bool isKey = false); CVarRef set(CStrRef key, CVarRef v, bool isKey = false); CVarRef set(CVarRef key, CVarRef v, bool isKey = false); @@ -336,9 +331,6 @@ class Array : protected SmartPtr { CVarRef set(int64_t key, RefResult v) { return setRef(key,variant(v)); } CVarRef set(double key, RefResult v) { return setRef(key,variant(v)); } - CVarRef set(litstr key, RefResult v, bool isKey = false) { - return setRef(key,variant(v), isKey); - } CVarRef set(CStrRef key, RefResult v, bool isKey = false) { return setRef(key,variant(v), isKey); } @@ -354,7 +346,6 @@ class Array : protected SmartPtr { return setRef(ToKey(key), v); } - CVarRef setRef(litstr key, CVarRef v, bool isKey = false); CVarRef setRef(CStrRef key, CVarRef v, bool isKey = false); CVarRef setRef(CVarRef key, CVarRef v, bool isKey = false); @@ -370,7 +361,6 @@ class Array : protected SmartPtr { return add(ToKey(key), v); } - CVarRef add(litstr key, CVarRef v, bool isKey = false); CVarRef add(CStrRef key, CVarRef v, bool isKey = false); CVarRef add(CVarRef key, CVarRef v, bool isKey = false); @@ -395,7 +385,6 @@ class Array : protected SmartPtr { return addLvalImpl(ToKey(key)); } - Variant &addLval(litstr key, bool isKey = false); Variant &addLval(CStrRef key, bool isKey = false); Variant &addLval(CVarRef key, bool isKey = false); @@ -422,7 +411,6 @@ class Array : protected SmartPtr { bool exists(double key) const { return existsImpl(ToKey(key)); } - bool exists(litstr key, bool isKey = false) const; bool exists(CStrRef key, bool isKey = false) const; bool exists(CVarRef key, bool isKey = false) const; @@ -448,7 +436,6 @@ class Array : protected SmartPtr { void remove(double key) { removeImpl(ToKey(key)); } - void remove(litstr key, bool isString = false); void remove(CStrRef key, bool isString = false); void remove(CVarRef key); @@ -486,6 +473,15 @@ class Array : protected SmartPtr { void setEvalScalar() const; + //litstr overloads + const Variant operator[](litstr key) const; + Variant rvalAt(litstr key, ACCESSPARAMS_DECL) const; + CVarRef rvalAtRef(litstr key, ACCESSPARAMS_DECL) const; + Variant &lval(litstr key); + Variant *lvalPtr(litstr key, bool forWrite, bool create); + Variant &lvalAt(litstr key, ACCESSPARAMS_DECL); + CVarRef set(litstr key, CVarRef v, bool isKey = false); + private: // helpers bool compare(CArrRef v2) const; diff --git a/hphp/runtime/base/type_string.h b/hphp/runtime/base/type_string.h index 54e278ccb..6ebb6eff4 100644 --- a/hphp/runtime/base/type_string.h +++ b/hphp/runtime/base/type_string.h @@ -291,7 +291,7 @@ public: */ String &operator = (StringData *data); String &operator = (litstr v); - String &operator = (CStrRef v); + String &operator = (const String& v); String &operator = (CVarRef v); String &operator = (const std::string &s); // These should be members, but g++ doesn't yet support the rvalue diff --git a/hphp/runtime/base/type_variant.h b/hphp/runtime/base/type_variant.h index 1132d7471..b3d65fbfc 100644 --- a/hphp/runtime/base/type_variant.h +++ b/hphp/runtime/base/type_variant.h @@ -1483,10 +1483,6 @@ inline const Variant Array::operator[](double key) const { return rvalAt(key); } -inline const Variant Array::operator[](litstr key) const { - return rvalAt(key); -} - inline const Variant Array::operator[](CStrRef key) const { return rvalAt(key); } @@ -1499,6 +1495,29 @@ inline Variant uninit_null() { return Variant(); } +//litstr overloads +inline const Variant Array::operator[](litstr key) const { + return (*this)[String(key)]; +} +inline Variant Array::rvalAt(litstr key, ACCESSPARAMS_IMPL) const { + return rvalAt(String(key), flags); +} +inline CVarRef Array::rvalAtRef(litstr key, ACCESSPARAMS_IMPL) const { + return rvalAtRef(String(key), flags); +} +inline Variant& Array::lval(litstr key) { + return lval(String(key)); +} +inline Variant* Array::lvalPtr(litstr key, bool forWrite, bool create) { + return lvalPtr(String(key), forWrite, create); +} +inline Variant& Array::lvalAt(litstr key, ACCESSPARAMS_IMPL) { + return lvalAt(String(key), flags); +} +inline CVarRef Array::set(litstr key, CVarRef v, bool isKey) { + return set(String(key), v, isKey); +} + /////////////////////////////////////////////////////////////////////////////// } diff --git a/hphp/runtime/eval/debugger/cmd/cmd_info.cpp b/hphp/runtime/eval/debugger/cmd/cmd_info.cpp index 3ae3f708a..1679ced77 100644 --- a/hphp/runtime/eval/debugger/cmd/cmd_info.cpp +++ b/hphp/runtime/eval/debugger/cmd/cmd_info.cpp @@ -23,6 +23,29 @@ namespace HPHP { namespace Eval { /////////////////////////////////////////////////////////////////////////////// +static const StaticString s_params("params"); +static const StaticString s_ref("ref"); +static const StaticString s_name("name"); +static const StaticString s_varg("varg"); +static const StaticString s_type("type"); +static const StaticString s_default("default"); +static const StaticString s_defaultext("defaultext"); +static const StaticString s_msg("msg"); +static const StaticString s_constants("constants"); +static const StaticString s_methods("methods"); +static const StaticString s_access("access"); +static const StaticString s_static("static"); +static const StaticString s_abstract("abstract"); +static const StaticString s_final("final"); +static const StaticString s_doc("doc"); +static const StaticString s_internal("internal"); +static const StaticString s_file("file"); +static const StaticString s_line1("line1"); +static const StaticString s_line2("line2"); +static const StaticString s_properties("properties"); +static const StaticString s_private_properties("private_properties"); +static const StaticString s_defaultText("defaultText"); + void CmdInfo::sendImpl(DebuggerThriftBuffer &thrift) { DebuggerCommand::sendImpl(thrift); thrift.write(m_type); @@ -172,12 +195,12 @@ String CmdInfo::GetProtoType(DebuggerClient *client, const std::string &cls, Array info = res->m_info; if (!info.empty()) { info = info[0]; - if (info.exists("params")) { + if (info.exists(s_params)) { StringBuffer sb; sb.printf("function %s%s(%s);\n", - info["ref"].toBoolean() ? "&" : "", - info["name"].toString().data(), - GetParams(info["params"], info["varg"]).data()); + info[s_ref].toBoolean() ? "&" : "", + info[s_name].toString().data(), + GetParams(info[s_params], info[s_varg]).data()); return sb.detach(); } } @@ -252,8 +275,8 @@ bool CmdInfo::onServer(DebuggerProxy *proxy) { /////////////////////////////////////////////////////////////////////////////// void CmdInfo::PrintDocComments(StringBuffer &sb, CArrRef info) { - if (info["doc"].isString()) { - String doc = info["doc"].toString(); + if (info[s_doc].isString()) { + String doc = info[s_doc].toString(); int space1 = 0; // best guess int space2 = 3; // best guess Variant matches1, matches2; @@ -271,10 +294,10 @@ void CmdInfo::PrintDocComments(StringBuffer &sb, CArrRef info) { void CmdInfo::PrintHeader(DebuggerClient *client, StringBuffer &sb, CArrRef info) { - if (!info["internal"].toBoolean()) { - String file = info["file"].toString(); - int line1 = info["line1"].toInt32(); - int line2 = info["line2"].toInt32(); + if (!info[s_internal].toBoolean()) { + String file = info[s_file].toString(); + int line1 = info[s_line1].toInt32(); + int line2 = info[s_line2].toInt32(); if (file.empty() && line1 == 0 && line2 == 0) { sb.printf("// (source unknown)\n"); } else if (line1 == 0 && line2 == 0) { @@ -301,30 +324,30 @@ String CmdInfo::GetParams(CArrRef params, bool varg, args.append(", "); } Array arg = iter.second().toArray(); - if (!arg["type"].toString().empty()) { - args.append(arg["type"].toString()); + if (!arg[s_type].toString().empty()) { + args.append(arg[s_type].toString()); args.append(' '); } - if (arg["ref"].toBoolean()) { + if (arg[s_ref].toBoolean()) { args.append('&'); } args.append('$'); - args.append(arg["name"].toString()); - if (arg.exists("default")) { + args.append(arg[s_name].toString()); + if (arg.exists(s_default)) { args.append(" = "); - Variant defValue = arg["default"]; - String defText = arg["defaultText"]; + Variant defValue = arg[s_default]; + String defText = arg[s_defaultText]; if (!defText.empty()) { args.append(defText); } else if (defValue.isObject()) { // ClassInfo was not able to serialize the value, so ext_reflection // prepared a stdClass error object. We should fall back to display // the original PHP text, if there. - args.append(defValue.o_get("msg").toString()); + args.append(defValue.o_get(s_msg).toString()); } else if (detailed) { - args.append(DebuggerClient::FormatVariable(arg["default"], -1)); + args.append(DebuggerClient::FormatVariable(arg[s_default], -1)); } else { - args.append(DebuggerClient::FormatVariable(arg["default"])); + args.append(DebuggerClient::FormatVariable(arg[s_default])); } } } @@ -337,11 +360,11 @@ String CmdInfo::GetParams(CArrRef params, bool varg, return args.detach(); } -String CmdInfo::GetModifier(CArrRef info, const char *name) { +String CmdInfo::GetModifier(CArrRef info, CStrRef name) { if (info[name].toBoolean()) { - return String(name) + " "; + return name + " "; } - return ""; + return empty_string; } String CmdInfo::FindSubSymbol(CArrRef symbols, const std::string &symbol) { @@ -356,11 +379,11 @@ String CmdInfo::FindSubSymbol(CArrRef symbols, const std::string &symbol) { bool CmdInfo::TryConstant(StringBuffer &sb, CArrRef info, const std::string &subsymbol) { - String key = FindSubSymbol(info["constants"], subsymbol); + String key = FindSubSymbol(info[s_constants], subsymbol); if (!key.isNull()) { sb.printf(" const %s = %s;\n", key.data(), DebuggerClient::FormatVariable - (info["constants"][key], -1).data()); + (info[s_constants][key], -1).data()); return true; } return false; @@ -368,27 +391,27 @@ bool CmdInfo::TryConstant(StringBuffer &sb, CArrRef info, bool CmdInfo::TryProperty(StringBuffer &sb, CArrRef info, const std::string &subsymbol) { - String key = FindSubSymbol(info["properties"], + String key = FindSubSymbol(info[s_properties], subsymbol[0] == '$' ? subsymbol.substr(1) : subsymbol); if (!key.isNull()) { - Array prop = info["properties"][key]; + Array prop = info[s_properties][key]; PrintDocComments(sb, prop); sb.printf(" %s %s$%s;\n", - prop["access"].toString().data(), - GetModifier(prop, "static").data(), - prop["name"].toString().data()); + prop[s_access].toString().data(), + GetModifier(prop, s_static).data(), + prop[s_name].toString().data()); return true; } - key = FindSubSymbol(info["private_properties"], + key = FindSubSymbol(info[s_private_properties], subsymbol[0] == '$' ? subsymbol.substr(1) : subsymbol); if (!key.isNull()) { - Array prop = info["private_properties"][key]; + Array prop = info[s_private_properties][key]; PrintDocComments(sb, prop); sb.printf(" private %s$%s;\n", - GetModifier(prop, "static").data(), - prop["name"].toString().data()); + GetModifier(prop, s_static).data(), + prop[s_name].toString().data()); return true; } return false; @@ -405,10 +428,10 @@ bool CmdInfo::TryMethod(DebuggerClient *client, StringBuffer &sb, CArrRef info, Array func = info["methods"][key].toArray(); PrintHeader(client, sb, func); sb.printf("%s %s%s%sfunction %s::%s%s(%s);\n", - func["access"].toString().data(), - GetModifier(func, "static").data(), - GetModifier(func, "final").data(), - GetModifier(func, "abstract").data(), + func[s_access].toString().data(), + GetModifier(func, s_static).data(), + GetModifier(func, s_final).data(), + GetModifier(func, s_abstract).data(), info["name"].toString().data(), func["ref"].toBoolean() ? "&" : "", func["name"].toString().data(), @@ -420,12 +443,12 @@ bool CmdInfo::TryMethod(DebuggerClient *client, StringBuffer &sb, CArrRef info, void CmdInfo::PrintInfo(DebuggerClient *client, StringBuffer &sb, CArrRef info, const std::string &subsymbol) { - if (info.exists("params")) { + if (info.exists(s_params)) { PrintHeader(client, sb, info); sb.printf("function %s%s(%s);\n", - info["ref"].toBoolean() ? "&" : "", - info["name"].toString().data(), - GetParams(info["params"], info["varg"]).data()); + info[s_ref].toBoolean() ? "&" : "", + info[s_name].toString().data(), + GetParams(info[s_params], info[s_varg]).data()); return; } @@ -463,8 +486,8 @@ void CmdInfo::PrintInfo(DebuggerClient *client, StringBuffer &sb, CArrRef info, parent = parents.detach(); sb.printf("%s%s%s %s %s{\n", - GetModifier(info, "final").data(), - GetModifier(info, "abstract").data(), + GetModifier(info, s_final).data(), + GetModifier(info, s_abstract).data(), info["interface"].toBoolean() ? "interface" : "class", info["name"].toString().data(), parent.data()); @@ -486,14 +509,14 @@ void CmdInfo::PrintInfo(DebuggerClient *client, StringBuffer &sb, CArrRef info, sb.printf(" %s%s %s$%s;\n", prop["doc"].toBoolean() ? "[doc] " : "", prop["access"].toString().data(), - GetModifier(prop, "static").data(), + GetModifier(prop, s_static).data(), prop["name"].toString().data()); } for (ArrayIter iter(info["private_properties"]); iter; ++iter) { Array prop = iter.second().toArray(); sb.printf(" %sprivate %s$%s;\n", prop["doc"].toBoolean() ? "[doc] " : "", - GetModifier(prop, "static").data(), + GetModifier(prop, s_static).data(), prop["name"].toString().data()); } } @@ -505,9 +528,9 @@ void CmdInfo::PrintInfo(DebuggerClient *client, StringBuffer &sb, CArrRef info, sb.printf(" %s%s %s%s%sfunction %s%s(%s);\n", func["doc"].toBoolean() ? "[doc] " : "", func["access"].toString().data(), - GetModifier(func, "static").data(), - GetModifier(func, "final").data(), - GetModifier(func, "abstract").data(), + GetModifier(func, s_static).data(), + GetModifier(func, s_final).data(), + GetModifier(func, s_abstract).data(), func["ref"].toBoolean() ? "&" : "", func["name"].toString().data(), GetParams(func["params"], func["varg"]).data()); diff --git a/hphp/runtime/eval/debugger/cmd/cmd_info.h b/hphp/runtime/eval/debugger/cmd/cmd_info.h index 2ae863017..695b1bb86 100644 --- a/hphp/runtime/eval/debugger/cmd/cmd_info.h +++ b/hphp/runtime/eval/debugger/cmd/cmd_info.h @@ -61,7 +61,7 @@ private: DebuggerClient::LiveListsPtr m_acLiveLists; static String GetParams(CArrRef params, bool varg, bool detailed = false); - static String GetModifier(CArrRef info, const char *name); + static String GetModifier(CArrRef info, CStrRef); static bool TryConstant(StringBuffer &sb, CArrRef info, const std::string &subsymbol); diff --git a/hphp/runtime/eval/debugger/cmd/cmd_variable.cpp b/hphp/runtime/eval/debugger/cmd/cmd_variable.cpp index 4306d073e..f6ec95057 100644 --- a/hphp/runtime/eval/debugger/cmd/cmd_variable.cpp +++ b/hphp/runtime/eval/debugger/cmd/cmd_variable.cpp @@ -146,9 +146,11 @@ void CmdVariable::setClientOutput(DebuggerClient *client) { client->setOTValues(values); } +static const StaticString s_GLOBALS("GLOBALS"); + Array CmdVariable::GetGlobalVariables() { Array ret = g_vmContext->m_globalVarEnv->getDefinedVariables(); - ret.remove("GLOBALS"); + ret.remove(s_GLOBALS); return ret; } diff --git a/hphp/runtime/eval/debugger/debugger_client.cpp b/hphp/runtime/eval/debugger/debugger_client.cpp index bb48cdf82..d228f1b8f 100644 --- a/hphp/runtime/eval/debugger/debugger_client.cpp +++ b/hphp/runtime/eval/debugger/debugger_client.cpp @@ -2079,25 +2079,32 @@ void DebuggerClient::moveToFrame(int index, bool display /* = true */) { } } +static const StaticString s_args("args"); +static const StaticString s_namespace("namespace"); +static const StaticString s_class("class"); +static const StaticString s_function("function"); +static const StaticString s_file("file"); +static const StaticString s_line("line"); + void DebuggerClient::printFrame(int index, CArrRef frame) { TRACE(2, "DebuggerClient::printFrame\n"); StringBuffer args; - for (ArrayIter iter(frame["args"]); iter; ++iter) { + for (ArrayIter iter(frame[s_args]); iter; ++iter) { if (!args.empty()) args.append(", "); String value = FormatVariable(iter.second()); args.append(value); } StringBuffer func; - if (frame.exists("namespace")) { - func.append(frame["namespace"].toString()); + if (frame.exists(s_namespace)) { + func.append(frame[s_namespace].toString()); func.append("::"); } - if (frame.exists("class")) { - func.append(frame["class"].toString()); + if (frame.exists(s_class)) { + func.append(frame[s_class].toString()); func.append("::"); } - func.append(frame["function"].toString()); + func.append(frame[s_function].toString()); String sindex(index); print("#%s %s (%s)\n %s at %s:%d", @@ -2105,8 +2112,8 @@ void DebuggerClient::printFrame(int index, CArrRef frame) { func.data() ? func.data() : "", args.data() ? args.data() : "", String(" ").substr(0, sindex.size()).data(), - frame["file"].toString().data(), - (int)frame["line"].toInt32()); + frame[s_file].toString().data(), + (int)frame[s_line].toInt32()); } void DebuggerClient::startMacro(std::string name) { diff --git a/hphp/runtime/ext/ext_debugger.cpp b/hphp/runtime/ext/ext_debugger.cpp index 95f359286..f574987c8 100644 --- a/hphp/runtime/ext/ext_debugger.cpp +++ b/hphp/runtime/ext/ext_debugger.cpp @@ -323,6 +323,11 @@ static const StaticString s_namespace("namespace"); static const StaticString s_class("class"); static const StaticString s_function("function"); static const StaticString s_text("text"); +static const StaticString s_user("user"); +static const StaticString s_configFName("configFName"); +static const StaticString s_host("host"); +static const StaticString s_port("port"); +static const StaticString s_sandbox("sandbox"); Variant c_DebuggerClientCmdUser::t_getcurrentlocation() { BreakPointInfoPtr bpi = m_client->getCurrentLocation(); @@ -410,15 +415,15 @@ Variant c_DebuggerClient::t_init(CVarRef options) { ops.apiMode = true; Array opsArr = options.toArray(); - if (opsArr.exists("user")) { - ops.user = opsArr.rvalAtRef("user").toString().data(); + if (opsArr.exists(s_user)) { + ops.user = opsArr.rvalAtRef(s_user).toString().data(); } else { raise_warning("must specify user in options"); return false; } - if (opsArr.exists("configFName")) { - ops.configFName = opsArr.rvalAtRef("configFName").toString().data(); + if (opsArr.exists(s_configFName)) { + ops.configFName = opsArr.rvalAtRef(s_configFName).toString().data(); FILE *f = fopen(ops.configFName.c_str(), "r"); if (!f) { raise_warning("cannot access config file %s", ops.configFName.c_str()); @@ -427,14 +432,14 @@ Variant c_DebuggerClient::t_init(CVarRef options) { fclose(f); } - if (opsArr.exists("host")) { - ops.host = opsArr.rvalAtRef("host").toString().data(); + if (opsArr.exists(s_host)) { + ops.host = opsArr.rvalAtRef(s_host).toString().data(); } - if (opsArr.exists("port")) { - ops.port = opsArr.rvalAtRef("port").toInt32(); + if (opsArr.exists(s_port)) { + ops.port = opsArr.rvalAtRef(s_port).toInt32(); } - if (opsArr.exists("sandbox")) { - ops.sandbox = opsArr.rvalAtRef("sandbox").toString().data(); + if (opsArr.exists(s_sandbox)) { + ops.sandbox = opsArr.rvalAtRef(s_sandbox).toString().data(); } m_client->init(ops); diff --git a/hphp/runtime/ext/ext_function.cpp b/hphp/runtime/ext/ext_function.cpp index 400ab97bd..83e355044 100644 --- a/hphp/runtime/ext/ext_function.cpp +++ b/hphp/runtime/ext/ext_function.cpp @@ -174,6 +174,8 @@ Variant f_call_user_func_array_rpc(CStrRef host, int port, CStrRef auth, static const StaticString s_func("func"); static const StaticString s_args("args"); +static const StaticString s_exception("exception"); +static const StaticString s_ret("ret"); Variant f_call_user_func_rpc(int _argc, CStrRef host, int port, CStrRef auth, int timeout, CVarRef function, @@ -228,17 +230,18 @@ Variant f_call_user_func_rpc(int _argc, CStrRef host, int port, CStrRef auth, return false; } - if (res.toArray().exists("exception")) { - throw res["exception"]; + if (res.toArray().exists(s_exception)) { + throw res[s_exception]; } - return res["ret"]; + return res[s_ret]; } Variant f_forward_static_call_array(CVarRef function, CArrRef params) { return f_forward_static_call(0, function, params); } -Variant f_forward_static_call(int _argc, CVarRef function, CArrRef _argv /* = null_array */) { +Variant f_forward_static_call(int _argc, CVarRef function, + CArrRef _argv /* = null_array */) { // Setting the bound parameter to true tells vm_call_user_func() // propogate the current late bound class return vm_call_user_func(function, _argv, true); diff --git a/hphp/runtime/ext/ext_image.cpp b/hphp/runtime/ext/ext_image.cpp index b1ce3b62e..681361446 100644 --- a/hphp/runtime/ext/ext_image.cpp +++ b/hphp/runtime/ext/ext_image.cpp @@ -763,7 +763,7 @@ static int php_read_APP(CObjRef stream, unsigned int marker, Variant &info) { snprintf((char*)markername, sizeof(markername), "APP%d", marker - M_APP0); if (!(info.is(KindOfArray) && - info.toArray().exists((const char *)markername))) { + info.toArray().exists(String((const char *)markername)))) { /* XXX we onyl catch the 1st tag of it's kind! */ info.set(String((char*)markername, CopyString), buffer); } diff --git a/hphp/runtime/ext/ext_openssl.cpp b/hphp/runtime/ext/ext_openssl.cpp index 8eb53e726..3be3c70ea 100644 --- a/hphp/runtime/ext/ext_openssl.cpp +++ b/hphp/runtime/ext/ext_openssl.cpp @@ -1160,6 +1160,9 @@ static STACK_OF(X509) *php_array_to_X509_sk(CVarRef certs) { return pcerts; } +static const StaticString s_friendly_name("friendly_name"); +static const StaticString s_extracerts("extracerts"); + static bool openssl_pkcs12_export_impl(CVarRef x509, BIO *bio_out, CVarRef priv_key, CStrRef pass, CVarRef args /* = null_variant */) { @@ -1183,13 +1186,13 @@ static bool openssl_pkcs12_export_impl(CVarRef x509, BIO *bio_out, Array arrArgs = args.toArray(); String friendly_name; - if (arrArgs.exists("friendly_name")) { - friendly_name = arrArgs["friendly_name"].toString(); + if (arrArgs.exists(s_friendly_name)) { + friendly_name = arrArgs[s_friendly_name].toString(); } STACK_OF(X509) *ca = NULL; - if (arrArgs.exists("extracerts")) { - ca = php_array_to_X509_sk(arrArgs["extracerts"]); + if (arrArgs.exists(s_extracerts)) { + ca = php_array_to_X509_sk(arrArgs[s_extracerts]); } PKCS12 *p12 = PKCS12_create @@ -1232,7 +1235,6 @@ bool f_openssl_pkcs12_export(CVarRef x509, VRefParam out, CVarRef priv_key, static const StaticString s_cert("cert"); static const StaticString s_pkey("pkey"); -static const StaticString s_extracerts("extracerts"); bool f_openssl_pkcs12_read(CStrRef pkcs12, VRefParam certs, CStrRef pass) { Variant &vcerts = certs; diff --git a/hphp/runtime/ext/ext_pdo.cpp b/hphp/runtime/ext/ext_pdo.cpp index e460340e0..bef835c06 100644 --- a/hphp/runtime/ext/ext_pdo.cpp +++ b/hphp/runtime/ext/ext_pdo.cpp @@ -2549,7 +2549,7 @@ rewrite: /* check if bound parameter is already available */ if (!strcmp(name.c_str(), "?") || - !stmt->bound_param_map.exists(name.c_str())) { + !stmt->bound_param_map.exists(name)) { idxbuf.printf(tmpl, bind_no++); } else { idxbuf.clear(); diff --git a/hphp/runtime/ext/ext_simplexml.cpp b/hphp/runtime/ext/ext_simplexml.cpp index 114272ab9..5de33f1f1 100644 --- a/hphp/runtime/ext/ext_simplexml.cpp +++ b/hphp/runtime/ext/ext_simplexml.cpp @@ -190,9 +190,10 @@ static Array create_children(CObjRef doc, xmlNodePtr root, } static inline void add_namespace_name(Array &out, xmlNsPtr ns) { - const char *prefix = ns->prefix ? (const char *)ns->prefix : ""; + String prefix = ns->prefix ? String((const char*)ns->prefix) : + String(empty_string); if (!out.exists(prefix)) { - out.set(String(prefix, CopyString), String((char*)ns->href, CopyString)); + out.set(prefix, String((char*)ns->href, CopyString)); } } diff --git a/hphp/runtime/ext/ext_soap.cpp b/hphp/runtime/ext/ext_soap.cpp index d897c28f4..668af4079 100644 --- a/hphp/runtime/ext/ext_soap.cpp +++ b/hphp/runtime/ext/ext_soap.cpp @@ -2046,6 +2046,8 @@ static bool valid_function(c_SoapServer *server, Object &soap_obj, return (f && f->isPublic()); } +static const StaticString s_HTTP_CONTENT_ENCODING("HTTP_CONTENT_ENCODING"); + void c_SoapServer::t_handle(CStrRef request /* = null_string */) { USE_SOAP_GLOBAL; SoapServerScope ss(this); @@ -2088,8 +2090,8 @@ void c_SoapServer::t_handle(CStrRef request /* = null_string */) { req = String(data, size, AttachLiteral); SystemGlobals *g = (SystemGlobals*)get_global_variables(); - if (g->GV(_SERVER).toArray().exists("HTTP_CONTENT_ENCODING")) { - String encoding = g->GV(_SERVER)["HTTP_CONTENT_ENCODING"]; + if (g->GV(_SERVER).toArray().exists(s_HTTP_CONTENT_ENCODING)) { + String encoding = g->GV(_SERVER)[s_HTTP_CONTENT_ENCODING]; Variant ret; if (encoding == "gzip" || encoding == "x-gzip") { ret = f_gzinflate(String(data, size, AttachLiteral)); diff --git a/hphp/runtime/ext/ext_xml.cpp b/hphp/runtime/ext/ext_xml.cpp index ae3bbdc7d..d78b2eb70 100644 --- a/hphp/runtime/ext/ext_xml.cpp +++ b/hphp/runtime/ext/ext_xml.cpp @@ -367,6 +367,7 @@ static const StaticString s_complete("complete"); static const StaticString s_tag("tag"); static const StaticString s_close("close"); static const StaticString s_level("level"); +static const StaticString s_value("value"); void _xml_endElementHandler(void *userData, const XML_Char *name) { XmlParser *parser = (XmlParser *)userData; @@ -447,13 +448,13 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) { if (parser->lastwasopen) { String myval; // check if value exists, if yes append to that - if (parser->ctag.toArray().exists("value")) + if (parser->ctag.toArray().exists(s_value)) { - myval = parser->ctag.rvalAt("value").toString(); + myval = parser->ctag.rvalAt(s_value).toString(); myval += String(decoded_value, decoded_len, AttachString); - parser->ctag.set("value", myval); + parser->ctag.set(s_value, myval); } else { - parser->ctag.set("value", + parser->ctag.set(s_value, String(decoded_value,decoded_len,AttachString)); } } else { @@ -462,15 +463,14 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) { String myval; String mytype; curtag.assignRef(parser->data.getArrayData()->endRef()); - if (curtag.toArray().exists("type")) { - mytype = curtag.rvalAt("type").toString(); - if (!strcmp(mytype.data(), "cdata")) { - if (curtag.toArray().exists("value")) { - myval = curtag.rvalAt("value").toString(); - myval += String(decoded_value, decoded_len, AttachString); - curtag.set("value", myval); - return; - } + if (curtag.toArray().exists(s_type)) { + mytype = curtag.rvalAt(s_type).toString(); + if (!strcmp(mytype.data(), "cdata") && + curtag.toArray().exists(s_value)) { + myval = curtag.rvalAt(s_value).toString(); + myval += String(decoded_value, decoded_len, AttachString); + curtag.set(s_value, myval); + return; } } tag = Array::Create(); diff --git a/hphp/runtime/ext/soap/encoding.cpp b/hphp/runtime/ext/soap/encoding.cpp index dfe0e14a3..d7bd31762 100644 --- a/hphp/runtime/ext/soap/encoding.cpp +++ b/hphp/runtime/ext/soap/encoding.cpp @@ -1169,7 +1169,7 @@ static bool get_zval_property(Variant &object, const char* name, } static void model_to_zval_any(Variant &ret, xmlNodePtr node) { - const char* name = NULL; + const char* name = nullptr; Variant any; while (node != NULL) { if (!get_zval_property(ret, (const char *)node->name)) { @@ -1212,8 +1212,9 @@ static void model_to_zval_any(Variant &ret, xmlNodePtr node) { } else { /* Add array element */ if (name) { - if (any.toArray().exists(name)) { - Variant &el = any.lvalAt(name); + String name_str(name); + if (any.toArray().exists(name_str)) { + Variant &el = any.lvalAt(name_str); if (!el.isArray()) { /* Convert into array */ Array arr = Array::Create(); @@ -1222,7 +1223,7 @@ static void model_to_zval_any(Variant &ret, xmlNodePtr node) { } el.append(val); } else { - any.set(String(name, CopyString), val); + any.set(name_str, val); } } else { any.append(val); diff --git a/hphp/runtime/vm/bytecode.cpp b/hphp/runtime/vm/bytecode.cpp index daf05836d..edde8b780 100644 --- a/hphp/runtime/vm/bytecode.cpp +++ b/hphp/runtime/vm/bytecode.cpp @@ -6733,6 +6733,8 @@ static inline void setContVar(const Func* genFunc, } } +static const StaticString s_this("this"); + c_Continuation* VMExecutionContext::fillContinuationVars(ActRec* fp, const Func* origFunc, @@ -6743,13 +6745,13 @@ VMExecutionContext::fillContinuationVars(ActRec* fp, // their references) between the evaluation stack and the local // space at the end of the object using memcpy. Any variables in a // VarEnv are saved and restored from m_vars as usual. - static const StringData* thisStr = StringData::GetStaticString("this"); + static const StringData* thisStr = s_this.get(); int nLocals = genFunc->numLocals(); bool skipThis; if (fp->hasVarEnv()) { Stats::inc(Stats::Cont_CreateVerySlow); Array definedVariables = fp->getVarEnv()->getDefinedVariables(); - skipThis = definedVariables.exists("this", true); + skipThis = definedVariables.exists(s_this, true); for (ArrayIter iter(definedVariables); !iter.end(); iter.next()) { setContVar(genFunc, iter.first().getStringData(), diff --git a/hphp/test/test_cpp_base.cpp b/hphp/test/test_cpp_base.cpp index 9a9a93872..ad98526ad 100644 --- a/hphp/test/test_cpp_base.cpp +++ b/hphp/test/test_cpp_base.cpp @@ -316,6 +316,12 @@ bool TestCppBase::TestArray() { VERIFY(arr1.toString() == "Array"); } + static const StaticString s_n1("n1"); + static const StaticString s_n2("n2"); + static const StaticString s_A("A"); + static const StaticString s_name("name"); + static const StaticString s_1("1"); + // offset { Array arr; @@ -325,8 +331,8 @@ bool TestCppBase::TestArray() { } { Array arr; - arr.set("n1", "v1"); - arr.set("n2", "v2"); + arr.set(s_n1, "v1"); + arr.set(s_n2, "v2"); VS(arr, CREATE_MAP2("n1", "v1", "n2", "v2")); } { @@ -337,8 +343,8 @@ bool TestCppBase::TestArray() { } { Array arr; - arr.lvalAt("n1") = "v1"; - arr.lvalAt("n2") = "v2"; + arr.lvalAt(s_n1) = "v1"; + arr.lvalAt(s_n2) = "v2"; VS(arr, CREATE_MAP2("n1", "v1", "n2", "v2")); } { @@ -349,17 +355,18 @@ bool TestCppBase::TestArray() { } { Array arr; - arr.lvalAt("A") = 10; - arr.lvalAt("A")++; - VS(arr["A"], 11); + arr.lvalAt(s_A) = 10; + arr.lvalAt(s_A)++; + VS(arr[s_A], 11); } + { Array arr; arr.lvalAt(1) = 10; VS(arr[1], 10); VS(arr[1.5], 10); VS(arr[Variant(1.5)], 10); - VS(arr["1"], 10); + VS(arr[s_1], 10); VS(arr[Variant("1")], 10); } { @@ -368,7 +375,7 @@ bool TestCppBase::TestArray() { VS(arr[1], 10); VS(arr[1.5], 10); VS(arr[Variant(1.5)], 10); - VS(arr["1"], 10); + VS(arr[s_1], 10); VS(arr[Variant("1")], 10); } { @@ -377,7 +384,7 @@ bool TestCppBase::TestArray() { VS(arr[1], 10); VS(arr[1.5], 10); VS(arr[Variant(1.5)], 10); - VS(arr["1"], 10); + VS(arr[s_1], 10); VS(arr[Variant("1")], 10); } { @@ -386,7 +393,7 @@ bool TestCppBase::TestArray() { VS(arr[1], 10); VS(arr[1.5], 10); VS(arr[Variant(1.5)], 10); - VS(arr["1"], 10); + VS(arr[s_1], 10); VS(arr[Variant("1")], 10); } @@ -403,10 +410,11 @@ bool TestCppBase::TestArray() { VS(arr, CREATE_MAP2(1, "v2", 2, "v3")); } { + static const StaticString s_0("0"); Array arr; arr.lvalAt(0) = "v1"; VERIFY(arr.exists(0)); - arr.remove("0"); + arr.remove(String(s_0)); VERIFY(!arr.exists(0)); } { @@ -433,18 +441,18 @@ bool TestCppBase::TestArray() { { Array arr; arr.lvalAt(Variant()) = 123; - VERIFY(arr.exists("")); + VERIFY(arr.exists(empty_string)); arr.remove(Variant()); - VERIFY(!arr.exists("")); + VERIFY(!arr.exists(empty_string)); } { Array arr; - arr.lvalAt("n1") = "v1"; - arr.lvalAt("n2") = "v2"; - VERIFY(arr.exists("n1")); - arr.remove("n1"); - VERIFY(!arr.exists("n1")); - VS(arr, Array::Create("n2", "v2")); + arr.lvalAt(s_n1) = "v1"; + arr.lvalAt(s_n2) = "v2"; + VERIFY(arr.exists(s_n1)); + arr.remove(s_n1); + VERIFY(!arr.exists(s_n1)); + VS(arr, Array::Create(s_n2, "v2")); arr.append("v3"); VS(arr, CREATE_MAP2("n2", "v2", 0, "v3")); } @@ -455,15 +463,15 @@ bool TestCppBase::TestArray() { } { Array arr; - arr.lvalAt("name") = "value"; - VERIFY(arr.exists("name")); + arr.lvalAt(s_name) = "value"; + VERIFY(arr.exists(s_name)); } { Array arr; arr.lvalAt(1) = "value"; VERIFY(arr.exists(1)); VERIFY(arr.exists(1.5)); - VERIFY(arr.exists("1")); + VERIFY(arr.exists(s_1)); VERIFY(arr.exists(Variant("1"))); VERIFY(arr.exists(Variant(1))); VERIFY(arr.exists(Variant(1.5))); @@ -473,7 +481,7 @@ bool TestCppBase::TestArray() { arr.lvalAt("1") = "value"; VERIFY(arr.exists(1)); VERIFY(arr.exists(1.5)); - VERIFY(arr.exists("1")); + VERIFY(arr.exists(s_1)); VERIFY(arr.exists(Variant("1"))); VERIFY(arr.exists(Variant(1))); VERIFY(arr.exists(Variant(1.5))); @@ -483,7 +491,7 @@ bool TestCppBase::TestArray() { arr.lvalAt(1.5) = "value"; VERIFY(arr.exists(1)); VERIFY(arr.exists(1.5)); - VERIFY(arr.exists("1")); + VERIFY(arr.exists(s_1)); VERIFY(arr.exists(Variant("1"))); VERIFY(arr.exists(Variant(1))); VERIFY(arr.exists(Variant(1.5))); @@ -493,7 +501,7 @@ bool TestCppBase::TestArray() { arr.lvalAt(Variant(1.5)) = "value"; VERIFY(arr.exists(1)); VERIFY(arr.exists(1.5)); - VERIFY(arr.exists("1")); + VERIFY(arr.exists(s_1)); VERIFY(arr.exists(Variant("1"))); VERIFY(arr.exists(Variant(1))); VERIFY(arr.exists(Variant(1.5))); @@ -503,7 +511,7 @@ bool TestCppBase::TestArray() { arr.lvalAt(Variant("1")) = "value"; VERIFY(arr.exists(1)); VERIFY(arr.exists(1.5)); - VERIFY(arr.exists("1")); + VERIFY(arr.exists(s_1)); VERIFY(arr.exists(Variant("1"))); VERIFY(arr.exists(Variant(1))); VERIFY(arr.exists(Variant(1.5))); diff --git a/hphp/test/test_ext_apc.cpp b/hphp/test/test_ext_apc.cpp index f583faab8..206119eb9 100644 --- a/hphp/test/test_ext_apc.cpp +++ b/hphp/test/test_ext_apc.cpp @@ -109,6 +109,11 @@ bool TestExtApc::test_apc_add() { return Count(true); } +static const StaticString s_a("a"); +static const StaticString s_q("q"); +static const StaticString s_ts("ts"); +static const StaticString s_TestString("TestString"); + bool TestExtApc::test_apc_store() { Array complexMap = CREATE_MAP2("a", CREATE_MAP2("b", 1, "c", @@ -129,9 +134,9 @@ bool TestExtApc::test_apc_store() { // Make sure it doesn't change the shared value. Array complexMapFetched = f_apc_fetch("complexMap"); - VERIFY(complexMapFetched.exists("a")); + VERIFY(complexMapFetched.exists(s_a)); complexMapFetched.set("q",0); - VERIFY(complexMapFetched.exists("q")); + VERIFY(complexMapFetched.exists(s_q)); VS(f_apc_fetch("complexMap"), complexMap); String tsFetched = f_apc_fetch("ts"); @@ -318,9 +323,9 @@ bool TestExtApc::test_apc_bin_loadfile() { } bool TestExtApc::test_apc_exists() { - f_apc_store("ts", "TestString"); - VS(f_apc_exists("ts"), true); - VS(f_apc_exists("TestString"), false); - VS(f_apc_exists(CREATE_VECTOR2("ts", "TestString")), CREATE_VECTOR1("ts")); + f_apc_store(s_ts, s_TestString); + VS(f_apc_exists(s_ts), true); + VS(f_apc_exists(s_TestString), false); + VS(f_apc_exists(CREATE_VECTOR2(s_ts, s_TestString)), CREATE_VECTOR1(s_ts)); return Count(true); } diff --git a/hphp/test/test_ext_array.cpp b/hphp/test/test_ext_array.cpp index e8e72d6f5..a799ff233 100644 --- a/hphp/test/test_ext_array.cpp +++ b/hphp/test/test_ext_array.cpp @@ -940,6 +940,8 @@ bool TestExtArray::test_array_shift() { return Count(true); } +static const StaticString s_a("a"); + bool TestExtArray::test_array_slice() { Array input = CREATE_VECTOR5("a", "b", "c", "d", "e"); @@ -969,12 +971,12 @@ bool TestExtArray::test_array_slice() { CREATE_VECTOR2("b", "c")); Array a = CREATE_MAP4("a", "g", 0, "a", 1, "b", 2, "c"); - a.remove("a"); + a.remove(s_a); VS(f_array_slice(a, 1, 2, true), CREATE_MAP2(1, "b", 2, "c")); VS(f_array_slice(a, 1, 2, false), CREATE_VECTOR2("b", "c")); a = CREATE_MAP4("a", 123, 0, "a", 1, "b", 2, "c"); - a.remove("a"); + a.remove(s_a); VS(f_array_slice(a, 1, 2, true), CREATE_MAP2(1, "b", 2, "c")); VS(f_array_slice(a, 1, 2, false), CREATE_VECTOR2("b", "c")); @@ -989,12 +991,12 @@ bool TestExtArray::test_array_slice() { bool TestExtArray::test_array_splice() { Variant params = CREATE_MAP2("a", "aaa", "0", "apple"); - params.remove("a"); + params.remove(s_a); f_array_splice(ref(params), 0, 0, CREATE_MAP1(123, "test")); VS(params, CREATE_VECTOR2("test", "apple")); params = CREATE_MAP2("a", "aaa", "1", "apple"); - params.remove("a"); + params.remove(s_a); f_array_splice(ref(params), 0, 0, CREATE_MAP1(123, "test")); VS(params, CREATE_VECTOR2("test", "apple")); diff --git a/hphp/test/test_ext_memcached.cpp b/hphp/test/test_ext_memcached.cpp index d7b84d47f..9bd5fa433 100644 --- a/hphp/test/test_ext_memcached.cpp +++ b/hphp/test/test_ext_memcached.cpp @@ -77,22 +77,39 @@ bool TestExtMemcached::test_Memcached_get_set() { return Count(true); } +static const StaticString s_boolean_true("boolean_true"); +static const StaticString s_boolean_false("boolean_false"); +static const StaticString s_string("string"); +static const StaticString s_string_empty("string_empty"); +static const StaticString + s_integer_positive_integer("integer_positive_integer"); +static const StaticString + s_integer_negative_integer("integer_negative_integer"); +static const StaticString s_integer_zero_integer("integer_zero_integer"); +static const StaticString s_float_positive1("float_positive1"); +static const StaticString s_float_positive2("float_positive2"); +static const StaticString s_float_negative("float_negative"); +static const StaticString s_float_zero("float_zero"); +static const StaticString s_null("null"); +static const StaticString s_array_empty("array_empty"); +static const StaticString s_array("array"); + bool TestExtMemcached::test_Memcached_types() { Array list; - list.add("boolean_true", true); - list.add("boolean_false", false); - list.add("string", "just a string"); - list.add("string_empty", ""); - list.add("integer_positive_integer", 10); - list.add("integer_negative_integer", -10); - list.add("integer_zero_integer", 0); - list.add("float_positive1", 3.912131); - list.add("float_positive2", 1.2131E+52); - list.add("float_negative", -42.123312); - list.add("float_zero", 0.0); - list.add("null", uninit_null()); - list.add("array_empty", Array()); - list.add("array", CREATE_VECTOR4(1, 2, 3, "foo")); + list.add(s_boolean_true, true); + list.add(s_boolean_false, false); + list.add(s_string, "just a string"); + list.add(s_string_empty, empty_string); + list.add(s_integer_positive_integer, 10); + list.add(s_integer_negative_integer, -10); + list.add(s_integer_zero_integer, 0); + list.add(s_float_positive1, 3.912131); + list.add(s_float_positive2, 1.2131E+52); + list.add(s_float_negative, -42.123312); + list.add(s_float_zero, 0.0); + list.add(s_null, uninit_null()); + list.add(s_array_empty, Array()); + list.add(s_array, CREATE_VECTOR4(1, 2, 3, "foo")); CREATE_MEMCACHED(); for (ArrayIter iter(list); iter; ++iter) {