Skip to content

Commit

Permalink
XPath: Always allocate xpath_strings on temporary stack for concat
Browse files Browse the repository at this point in the history
The static_buffer optimization seems to come from the time where the
on-heap buffer was allocated using global memory operations. At this
point the temporary buffer and temporary string storage all come from
the evaluation stack (that can be partially allocated on heap...), so
the extra logic isn't relevant for performance.
  • Loading branch information
zeux committed Nov 14, 2017
1 parent 7c6d001 commit 344c74a
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10442,16 +10442,9 @@ PUGI__NS_BEGIN
size_t count = 1;
for (xpath_ast_node* nc = _right; nc; nc = nc->_next) count++;

// gather all strings
xpath_string static_buffer[4];
xpath_string* buffer = static_buffer;

// allocate on-heap for large concats
if (count > sizeof(static_buffer) / sizeof(static_buffer[0]))
{
buffer = static_cast<xpath_string*>(stack.temp->allocate(count * sizeof(xpath_string)));
if (!buffer) return xpath_string();
}
// allocate a buffer for temporary string objects
xpath_string* buffer = static_cast<xpath_string*>(stack.temp->allocate(count * sizeof(xpath_string)));
if (!buffer) return xpath_string();

// evaluate all strings to temporary stack
xpath_stack swapped_stack = {stack.temp, stack.result};
Expand Down

0 comments on commit 344c74a

Please sign in to comment.