Skip to content

Commit

Permalink
improve performance in simplexml
Browse files Browse the repository at this point in the history
Summary: When casting a SimpleXML element to boolean, we're only concerned with
the object having an XML node, *or* having attributes. Building
attributes is done by sxe_get_prop_hash that also recursively builds the
entire element tree starting from that element.

We shortcircuit when the object has a valid XML node to prevent excessive
amount of object creation when all your program is doing is loading
XML strings and doing read/toBool operations.

Before: http://i.imgur.com/TFFj97u.gif
After:  http://i.imgur.com/3kNpwIM.gif
Closes facebook#2855

Reviewed By: @scannell

Differential Revision: D1364022

Pulled By: @JoelMarcey
  • Loading branch information
danslo authored and JoelMarcey committed Jun 5, 2014
1 parent d24e584 commit ea535b8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hphp/runtime/ext/ext_simplexml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,10 @@ static void sxe_get_prop_hash(c_SimpleXMLElement* sxe, bool is_debug,
static Variant sxe_object_cast(c_SimpleXMLElement* sxe, int8_t type) {
if (type == HPHP::KindOfBoolean) {
xmlNodePtr node = php_sxe_get_first_node(sxe, nullptr);
if (node) return true;
Array properties = Array::Create();
sxe_get_prop_hash(sxe, true, properties);
return node != nullptr || properties.size();
return properties.size() != 0;
}

xmlChar* contents = nullptr;
Expand Down

0 comments on commit ea535b8

Please sign in to comment.