Small cleanup for ObjectData and a few other things

This diff addresses most of the diff review feedback from D740016.
Esse commit está contido em:
Drew Paroski
2013-06-30 01:49:39 -07:00
commit de Sara Golemon
commit 1ee3810e21
6 arquivos alterados com 26 adições e 31 exclusões
+9 -9
Ver Arquivo
@@ -55,7 +55,7 @@ ObjectData::~ObjectData() {
}
}
bool ObjectData::instanceof(const HPHP::Class* c) const {
bool ObjectData::instanceof(const Class* c) const {
return m_cls->classof(c);
}
@@ -113,7 +113,7 @@ CStrRef ObjectData::o_getClassNameHook() const {
HOT_FUNC
bool ObjectData::o_instanceof(CStrRef s) const {
HPHP::Class* cls = Unit::lookupClass(s.get());
Class* cls = Unit::lookupClass(s.get());
if (!cls) return false;
return m_cls->classof(cls);
}
@@ -185,7 +185,7 @@ MutableArrayIter ObjectData::begin(Variant *key, Variant &val,
}
void ObjectData::initProperties(int nProp) {
if (!o_properties.get()) ((HPHP::Instance*)this)->initDynProps(nProp);
if (!o_properties.get()) ((Instance*)this)->initDynProps(nProp);
}
Variant* ObjectData::o_realProp(CStrRef propName, int flags,
@@ -196,12 +196,12 @@ Variant* ObjectData::o_realProp(CStrRef propName, int flags,
* behavior in cases where the named property is nonexistent or
* inaccessible.
*/
HPHP::Class* ctx = nullptr;
Class* ctx = nullptr;
if (!context.empty()) {
ctx = Unit::lookupClass(context.get());
}
HPHP::Instance* thiz = (HPHP::Instance*)(this); // sigh
Instance* thiz = (Instance*)this; // sigh
bool visible, accessible, unset;
TypedValue* ret = (flags & RealPropNoDynamic)
? thiz->getDeclProp(ctx, propName.get(), visible,
@@ -270,7 +270,7 @@ inline ALWAYS_INLINE Variant ObjectData::o_setImpl(CStrRef propName, T v,
}
bool useSet = !forInit && getAttribute(UseSet);
int flags = useSet ? 0 : RealPropCreate;
auto flags = useSet ? 0 : RealPropCreate;
if (forInit) flags |= RealPropUnchecked;
if (Variant *t = o_realProp(propName, flags, context)) {
@@ -357,7 +357,7 @@ void ObjectData::o_getArray(Array &props, bool pubOnly /* = false */) const {
auto thiz = static_cast<const Instance*>(this);
do {
thiz->getProps(cls, pubOnly, cls->m_preClass.get(), props, inserted);
const std::vector<ClassPtr> &usedTraits = cls->m_usedTraits;
auto& usedTraits = cls->m_usedTraits;
for (unsigned t = 0; t < usedTraits.size(); t++) {
const ClassPtr& trait = usedTraits[t];
thiz->getProps(cls, pubOnly, trait->m_preClass.get(), props, inserted);
@@ -622,7 +622,7 @@ void ObjectData::serializeImpl(VariableSerializer *serializer) const {
if (UNLIKELY(handleSleep)) {
assert(!isCollection());
if (ret.isArray()) {
auto thiz = (Instance*)(this);
auto thiz = (Instance*)this;
Array wanted = Array::Create();
Array props = ret.toArray();
for (ArrayIter iter(props); iter; ++iter) {
@@ -710,7 +710,7 @@ void ObjectData::dump() const {
}
ObjectData *ObjectData::clone() {
HPHP::Instance* instance = static_cast<HPHP::Instance*>(this);
Instance* instance = static_cast<Instance*>(this);
return instance->cloneImpl();
}
+3 -3
Ver Arquivo
@@ -72,9 +72,9 @@ class ObjectData : public CountableNF {
};
enum {
RealPropCreate = 1, // Property should be created if it doesnt exist
RealPropNoDynamic = 4, // Dont return dynamic properties
RealPropUnchecked = 8, // Dont check property accessibility
RealPropCreate = 1, // Property should be created if it doesn't exist
RealPropNoDynamic = 4, // Don't return dynamic properties
RealPropUnchecked = 8, // Don't check property accessibility
RealPropExist = 16, // For property_exists
};
+2 -3
Ver Arquivo
@@ -904,14 +904,13 @@ bool BreakPointInfo::MatchClass(const char *fcls, const std::string &bcls,
StackStringData sdBClsName(bcls.c_str());
Class* clsB = Unit::lookupClass(&sdBClsName);
if (!clsB) return false;
StackStringData sdFClsName(fcls);
Class* clsF = Unit::lookupClass(&sdFClsName);
if (!clsB) return false;
if (clsB == clsF) return true;
StackStringData sdFuncName(func);
Func* f = clsB->lookupMethod(&sdFuncName);
if (!f) return false;
return (f->baseCls() == clsF);
return f && f->baseCls() == clsF;
}
bool BreakPointInfo::Match(const char *haystack, int haystack_len,
+3 -1
Ver Arquivo
@@ -431,12 +431,14 @@ void utf16_to_utf8(StringBuffer &buf, unsigned short utf16) {
}
}
StaticString s__empty_("_empty_");
static void object_set(Variant &var, CStrRef key, CVarRef value,
int assoc) {
if (!assoc) {
// We know it is stdClass, and everything is public (and dynamic).
if (key.empty()) {
var.getObjectData()->o_set("_empty_", value);
var.getObjectData()->o_set(s__empty_, value);
} else {
var.getObjectData()->o_set(key, value);
}
+6 -6
Ver Arquivo
@@ -105,7 +105,7 @@ Array f_get_class_methods(CVarRef class_or_object) {
}
Array vm_get_class_constants(CStrRef className) {
HPHP::Class* cls = HPHP::Unit::loadClass(className.get());
Class* cls = Unit::loadClass(className.get());
if (cls == NULL) {
return ArrayData::Make(0);
}
@@ -135,7 +135,7 @@ Array f_get_class_constants(CStrRef class_name) {
}
Array vm_get_class_vars(CStrRef className) {
HPHP::Class* cls = HPHP::Unit::lookupClass(className.get());
Class* cls = Unit::lookupClass(className.get());
if (cls == NULL) {
raise_error("Unknown class %s", className->data());
}
@@ -157,7 +157,7 @@ Array vm_get_class_vars(CStrRef className) {
// For visibility checks
CallerFrame cf;
HPHP::Class* ctx = arGetContextClass(cf());
Class* ctx = arGetContextClass(cf());
auto ret = ArrayData::Make(numDeclProps + numSProps);
@@ -194,7 +194,7 @@ Variant f_get_class(CVarRef object /* = null_variant */) {
// No arg passed.
String ret;
CallerFrame cf;
HPHP::Class* cls = arGetContextClassImpl<true>(cf());
Class* cls = arGetContextClassImpl<true>(cf());
if (cls) {
ret = CStrRef(cls->nameRef());
}
@@ -212,7 +212,7 @@ Variant f_get_class(CVarRef object /* = null_variant */) {
Variant f_get_parent_class(CVarRef object /* = null_variant */) {
if (!object.isInitialized()) {
CallerFrame cf;
HPHP::Class* cls = arGetContextClass(cf());
Class* cls = arGetContextClass(cf());
if (cls && cls->parent()) {
return CStrRef(cls->parentRef());
}
@@ -230,7 +230,7 @@ Variant f_get_parent_class(CVarRef object /* = null_variant */) {
Class* cls = Unit::lookupClass(class_name.toString().get());
if (cls) {
CStrRef parentClass = *(const String*)(&cls->parentRef());
auto& parentClass = *(const String*)(&cls->parentRef());
if (!parentClass.empty()) {
return parentClass;
}
+3 -9
Ver Arquivo
@@ -242,8 +242,6 @@ static void add_registered_namespaces(Array &out, xmlNodePtr node,
///////////////////////////////////////////////////////////////////////////////
// simplexml
static StaticString s_SimpleXMLElement("SimpleXMLElement");
Variant f_simplexml_import_dom(CObjRef node,
CStrRef class_name /* = "SimpleXMLElement" */) {
@@ -275,14 +273,9 @@ Variant f_simplexml_load_string(CStrRef data,
int64_t options /* = 0 */,
CStrRef ns /* = "" */,
bool is_prefix /* = false */) {
if (!f_class_exists(class_name)) {
throw_invalid_argument("class %s does not exist", class_name.data());
return uninit_null();
}
Class* cls;
if (!class_name.empty()) {
cls = Unit::lookupClass(class_name.get());
cls = Unit::loadClass(class_name.get());
if (!cls) {
throw_invalid_argument("class not found: %s", class_name.data());
return uninit_null();
@@ -357,7 +350,8 @@ void c_SimpleXMLElement::t___construct(CStrRef data, int64_t options /* = 0 */,
xmlDocPtr doc = xmlReadMemory(xml.data(), xml.size(), NULL, NULL, options);
if (doc) {
m_doc = Object(NEWOBJ(XmlDocWrapper)(doc, s_SimpleXMLElement));
m_doc =
Object(NEWOBJ(XmlDocWrapper)(doc, c_SimpleXMLElement::s_class_name));
m_node = xmlDocGetRootElement(doc);
if (m_node) {
m_children = create_children(m_doc, m_node, ns, is_prefix);