diff options
author | arseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640> | 2012-11-17 21:52:02 +0000 |
---|---|---|
committer | arseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640> | 2012-11-17 21:52:02 +0000 |
commit | ed30b95a4286b57c572e74200ce84d72d443bbfa (patch) | |
tree | 114250685295aefef98c6ec0aee9fec86ba42934 /src/pugixml.cpp | |
parent | 971fd967641225977f150d6204e85733a3084212 (diff) |
XPath stack optimization: Reduce stack usage during parsing by sharing scratch buffer for variable/number parsing (we only need one per parser)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@928 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r-- | src/pugixml.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp index da6d447..ffccdd7 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -6440,10 +6440,8 @@ PUGI__NS_BEGIN #endif } - PUGI__FN bool convert_string_to_number(const char_t* begin, const char_t* end, double* out_result) + PUGI__FN bool convert_string_to_number(char_t (&buffer)[32], const char_t* begin, const char_t* end, double* out_result) { - char_t buffer[32]; - size_t length = static_cast<size_t>(end - begin); char_t* scratch = buffer; @@ -6736,10 +6734,8 @@ PUGI__NS_BEGIN } } - PUGI__FN xpath_variable* get_variable(xpath_variable_set* set, const char_t* begin, const char_t* end) + PUGI__FN xpath_variable* get_variable(char_t (&buffer)[32], xpath_variable_set* set, const char_t* begin, const char_t* end) { - char_t buffer[32]; - size_t length = static_cast<size_t>(end - begin); char_t* scratch = buffer; @@ -8730,6 +8726,8 @@ PUGI__NS_BEGIN xpath_parse_result* _result; + char_t _scratch[32]; + #ifdef PUGIXML_NO_EXCEPTIONS jmp_buf _error_handler; #endif @@ -9018,7 +9016,7 @@ PUGI__NS_BEGIN if (!_variables) throw_error("Unknown variable: variable set is not provided"); - xpath_variable* var = get_variable(_variables, name.begin, name.end); + xpath_variable* var = get_variable(_scratch, _variables, name.begin, name.end); if (!var) throw_error("Unknown variable: variable set does not contain the given name"); @@ -9056,7 +9054,7 @@ PUGI__NS_BEGIN { double value = 0; - if (!convert_string_to_number(_lexer.contents().begin, _lexer.contents().end, &value)) + if (!convert_string_to_number(_scratch, _lexer.contents().begin, _lexer.contents().end, &value)) throw_error_oom(); xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_number_constant, xpath_type_number, value); |