From e8e54ea5de080d33780c68847057adf82c12ec16 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 17 Oct 2015 10:24:53 -0700 Subject: Use explicit tests in set_Name/set_value Node type enum is not used as an array index anywhere else; the code is not very readable and the value of this "optimization" is questionable. The conditions are arranged so that in all normal cases the first comparison returns true anyway. --- src/pugixml.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 8fb3cdc..694a1a6 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -5449,9 +5449,9 @@ namespace pugi PUGI__FN bool xml_node::set_name(const char_t* rhs) { - static const bool has_name[] = { false, false, true, false, false, false, true, true, false }; + xml_node_type type_ = _root ? PUGI__NODETYPE(_root) : node_null; - if (!_root || !has_name[PUGI__NODETYPE(_root)]) + if (type_ != node_element && type_ != node_pi && type_ != node_declaration) return false; return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); @@ -5459,9 +5459,9 @@ namespace pugi PUGI__FN bool xml_node::set_value(const char_t* rhs) { - static const bool has_value[] = { false, false, false, true, true, true, true, false, true }; + xml_node_type type_ = _root ? PUGI__NODETYPE(_root) : node_null; - if (!_root || !has_value[PUGI__NODETYPE(_root)]) + if (type_ != node_pcdata && type_ != node_cdata && type_ != node_comment && type_ != node_pi && type_ != node_doctype) return false; return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)); -- cgit v1.2.3