mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-28 06:10:55 +08:00
XPath: Always allocate xpath_strings on temporary stack for concat
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.
This commit is contained in:
parent
7c6d0010b3
commit
344c74a74c
@ -10442,16 +10442,9 @@ PUGI__NS_BEGIN
|
|||||||
size_t count = 1;
|
size_t count = 1;
|
||||||
for (xpath_ast_node* nc = _right; nc; nc = nc->_next) count++;
|
for (xpath_ast_node* nc = _right; nc; nc = nc->_next) count++;
|
||||||
|
|
||||||
// gather all strings
|
// allocate a buffer for temporary string objects
|
||||||
xpath_string static_buffer[4];
|
xpath_string* buffer = static_cast<xpath_string*>(stack.temp->allocate(count * sizeof(xpath_string)));
|
||||||
xpath_string* buffer = static_buffer;
|
if (!buffer) return xpath_string();
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// evaluate all strings to temporary stack
|
// evaluate all strings to temporary stack
|
||||||
xpath_stack swapped_stack = {stack.temp, stack.result};
|
xpath_stack swapped_stack = {stack.temp, stack.result};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user