summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-11-18 23:11:59 +0000
committerarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-11-18 23:11:59 +0000
commita3aa5d39b82c33b651d5e61094ec4e9ef87de455 (patch)
treeb28b74bccbd716b2535aa050c0787d1b1347a4df
parentc95900e354946e558a3b4b9396b9f8198385262a (diff)
XPath stack optimization: Reduce convert_number_to_string stack usage by reducing mantissa_buffer size and filling resulting string on heap without an extra copy from stack.
git-svn-id: http://pugixml.googlecode.com/svn/trunk@933 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--src/pugixml.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 83f5329..163ac48 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -6341,14 +6341,18 @@ PUGI__NS_BEGIN
if (special) return xpath_string_const(special);
// get mantissa + exponent form
- char mantissa_buffer[64];
+ char mantissa_buffer[32];
char* mantissa;
int exponent;
convert_number_to_mantissa_exponent(value, mantissa_buffer, sizeof(mantissa_buffer), &mantissa, &exponent);
+ // allocate a buffer of suitable length for the number
+ size_t result_size = strlen(mantissa_buffer) + (exponent > 0 ? exponent : -exponent) + 4;
+ char_t* result = static_cast<char_t*>(alloc->allocate(sizeof(char_t) * result_size));
+ assert(result);
+
// make the number!
- char_t result[512];
char_t* s = result;
// sign
@@ -6391,10 +6395,10 @@ PUGI__NS_BEGIN
}
// zero-terminate
- assert(s < result + sizeof(result) / sizeof(result[0]));
+ assert(s < result + result_size);
*s = 0;
- return xpath_string(result, alloc);
+ return xpath_string(result, true);
}
PUGI__FN bool check_string_to_number_format(const char_t* string)