diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2015-10-17 10:24:53 -0700 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2015-10-17 10:26:57 -0700 |
commit | e8e54ea5de080d33780c68847057adf82c12ec16 (patch) | |
tree | 6a5a948ec3855987551b2dad961779f5c5c405a9 | |
parent | 122157eb0e58977a290f33dcbeff349d6099f925 (diff) |
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.
-rw-r--r-- | src/pugixml.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
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)); |