-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: measure impact of event stack as a CRTP
- Loading branch information
Showing
4 changed files
with
137 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
#ifndef _has_any_ | ||
#error "must define _has_any_()" | ||
#endif | ||
|
||
detail::stack<state> m_stack; | ||
state *C4_RESTRICT m_curr; ///< current stack level: top of the stack. cached here for easier access. | ||
state *C4_RESTRICT m_parent; ///< parent of the current stack level. | ||
|
||
void _stack_reset_root() | ||
{ | ||
m_stack.clear(); | ||
m_stack.push({}); | ||
m_parent = nullptr; | ||
m_curr = &m_stack.top(); | ||
} | ||
|
||
void _stack_reset_non_root() | ||
{ | ||
m_stack.clear(); | ||
m_stack.push({}); // parent | ||
m_stack.push({}); // node | ||
m_parent = &m_stack.top(1); | ||
m_curr = &m_stack.top(); | ||
} | ||
|
||
void _stack_push() | ||
{ | ||
m_stack.push_top(); | ||
m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push | ||
m_curr = &m_stack.top(); | ||
m_curr->reset_after_push(); | ||
} | ||
|
||
void _stack_pop() | ||
{ | ||
_RYML_CB_ASSERT(m_stack.m_callbacks, m_parent); | ||
_RYML_CB_ASSERT(m_stack.m_callbacks, m_stack.size() > 1); | ||
m_parent->reset_before_pop(*m_curr); | ||
m_stack.pop(); | ||
m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr; | ||
m_curr = &m_stack.top(); | ||
#ifdef RYML_DBG | ||
if(m_parent) | ||
_c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id); | ||
else | ||
_c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id); | ||
#endif | ||
} | ||
|
||
bool _stack_should_push_on_begin_doc() const | ||
{ | ||
const bool is_root = (m_stack.size() == 1u); | ||
return is_root && (_has_any_(DOC|VAL|MAP|SEQ) || m_curr->has_children); | ||
} | ||
|
||
bool _stack_should_pop_on_end_doc() const | ||
{ | ||
const bool is_root = (m_stack.size() == 1u); | ||
return !is_root && _has_any_(DOC); | ||
} | ||
|
||
/** Check whether the current parse tokens are trailing on the | ||
* previous doc, and raise an error if they are. This function is | ||
* called by the parse engine (not the event handler) before a doc | ||
* is started. */ | ||
void check_trailing_doc_token() const | ||
{ | ||
const bool is_root = (m_stack.size() == 1u); | ||
const bool isndoc = (m_curr->flags & NDOC) != 0; | ||
const bool suspicious = _has_any_(MAP|SEQ|VAL); | ||
_c4dbgpf("target={} isroot={} suspicious={} ndoc={}", m_curr->node_id, is_root, suspicious, isndoc); | ||
if((is_root || _has_any_(DOC)) && suspicious && !isndoc) | ||
_RYML_CB_ERR_(m_stack.m_callbacks, "parse error", m_curr->pos); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters