Refactor accessing node type into a macro

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1042 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
Arseny Kapoulkine 2014-10-03 02:37:22 +00:00
parent e376ba731f
commit f729fee60a

View File

@ -275,6 +275,8 @@ PUGI__NS_BEGIN
static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = xml_memory_page_name_allocated_mask | xml_memory_page_name_or_value_shared_mask; static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = xml_memory_page_name_allocated_mask | xml_memory_page_name_or_value_shared_mask;
static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = xml_memory_page_value_allocated_mask | xml_memory_page_name_or_value_shared_mask; static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = xml_memory_page_value_allocated_mask | xml_memory_page_name_or_value_shared_mask;
#define PUGI__NODETYPE(n) static_cast<xml_node_type>(((n)->header & impl::xml_memory_page_type_mask) + 1)
struct xml_allocator; struct xml_allocator;
struct xml_memory_page struct xml_memory_page
@ -2727,7 +2729,7 @@ PUGI__NS_BEGIN
if (!s) return s; if (!s) return s;
assert(cursor); assert(cursor);
if ((cursor->header & xml_memory_page_type_mask) + 1 == node_declaration) goto LOC_ATTRIBUTES; if (PUGI__NODETYPE(cursor) == node_declaration) goto LOC_ATTRIBUTES;
} }
else if (*s == '!') // '<!...' else if (*s == '!') // '<!...'
{ {
@ -2808,8 +2810,7 @@ PUGI__NS_BEGIN
{ {
while (node) while (node)
{ {
xml_node_type type = static_cast<xml_node_type>((node->header & impl::xml_memory_page_type_mask) + 1); if (PUGI__NODETYPE(node) == node_element) return true;
if (type == node_element) return true;
node = node->next_sibling; node = node->next_sibling;
} }
@ -3696,7 +3697,7 @@ PUGI__NS_BEGIN
inline bool is_text_node(xml_node_struct* node) inline bool is_text_node(xml_node_struct* node)
{ {
xml_node_type type = static_cast<xml_node_type>((node->header & impl::xml_memory_page_type_mask) + 1); xml_node_type type = PUGI__NODETYPE(node);
return type == node_pcdata || type == node_cdata; return type == node_pcdata || type == node_cdata;
} }
@ -4627,7 +4628,7 @@ namespace pugi
PUGI__FN xml_node_type xml_node::type() const PUGI__FN xml_node_type xml_node::type() const
{ {
return _root ? static_cast<xml_node_type>((_root->header & impl::xml_memory_page_type_mask) + 1) : node_null; return _root ? PUGI__NODETYPE(_root) : node_null;
} }
PUGI__FN const char_t* xml_node::value() const PUGI__FN const char_t* xml_node::value() const
@ -6056,7 +6057,7 @@ namespace pugi
assert(_root); assert(_root);
for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling)
if ((i->header & impl::xml_memory_page_type_mask) + 1 == node_element) if (PUGI__NODETYPE(i) == node_element)
return xml_node(i); return xml_node(i);
return xml_node(); return xml_node();
@ -10965,6 +10966,7 @@ namespace pugi
#undef PUGI__NS_END #undef PUGI__NS_END
#undef PUGI__FN #undef PUGI__FN
#undef PUGI__FN_NO_INLINE #undef PUGI__FN_NO_INLINE
#undef PUGI__NODETYPE
#undef PUGI__IS_CHARTYPE_IMPL #undef PUGI__IS_CHARTYPE_IMPL
#undef PUGI__IS_CHARTYPE #undef PUGI__IS_CHARTYPE
#undef PUGI__IS_CHARTYPEX #undef PUGI__IS_CHARTYPEX