From ea535b8292e8fdf271762e9a9bc949c64c40fc7a Mon Sep 17 00:00:00 2001 From: Daniel Sloof Date: Wed, 4 Jun 2014 13:24:19 -0700 Subject: [PATCH] improve performance in simplexml 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 #2855 Reviewed By: @scannell Differential Revision: D1364022 Pulled By: @JoelMarcey --- hphp/runtime/ext/ext_simplexml.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hphp/runtime/ext/ext_simplexml.cpp b/hphp/runtime/ext/ext_simplexml.cpp index 6db12154cd0456..1de5b5975e50d1 100644 --- a/hphp/runtime/ext/ext_simplexml.cpp +++ b/hphp/runtime/ext/ext_simplexml.cpp @@ -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;