From 7fab1bf757700449b9dead756989d08e3114182a Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 29 Aug 2010 15:26:06 +0000 Subject: tests: Reduced allocation count git-svn-id: http://pugixml.googlecode.com/svn/trunk@662 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath_xalan_2.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'tests/test_xpath_xalan_2.cpp') diff --git a/tests/test_xpath_xalan_2.cpp b/tests/test_xpath_xalan_2.cpp index aa8ae17..4ab4928 100644 --- a/tests/test_xpath_xalan_2.cpp +++ b/tests/test_xpath_xalan_2.cpp @@ -5,6 +5,7 @@ #include "common.hpp" #include +#include TEST_XML(xpath_xalan_string_1, "ENCYCLOPEDIA") { @@ -129,38 +130,53 @@ TEST_XML(xpath_xalan_string_4, "abcdef number_to_string(int number) +static const char_t* number_to_string_unsafe(int number) { - std::basic_string result; + static char_t buffer[16]; + + // construct number in reverse + char_t* it = buffer; while (number) { - result = static_cast('0' + number % 10) + result; + *it++ = static_cast('0' + number % 10); number /= 10; } - return result; + // zero terminate + *it = 0; + + // reverse to get final result + std::reverse(buffer, it); + + return buffer; } TEST(xpath_xalan_string_5) { - std::basic_string query = STR("concat("); + const int count = 1000; + + std::basic_string query; + query.reserve(17 * count); + + query += STR("concat("); - for (int i = 1; i < 1000; ++i) + for (int i = 1; i < count; ++i) { query += STR("concat('t',"); - query += number_to_string(i); + query += number_to_string_unsafe(i); query += STR("), "); } query += STR("'')"); std::basic_string expected; + expected.reserve(4 * count); - for (int j = 1; j < 1000; ++j) + for (int j = 1; j < count; ++j) { expected += STR("t"); - expected += number_to_string(j); + expected += number_to_string_unsafe(j); } CHECK_XPATH_STRING(xml_node(), query.c_str(), expected.c_str()); -- cgit v1.2.3