mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-16 15:01:15 +02:00
Use map from key to count instead of multiset (#3885)
* Test that enumerates lots of elements with the same name * Use map from key to count instead of multiset Co-authored-by: Alexander Gololobov <{ID}+{username}@users.noreply.github.com>
This commit is contained in:
parent
079b50e0c1
commit
0fd1749b81
@ -266,7 +266,7 @@ void XMLConfiguration::enumerate(const std::string& key, Keys& range) const
|
|||||||
{
|
{
|
||||||
using Poco::NumberFormatter;
|
using Poco::NumberFormatter;
|
||||||
|
|
||||||
std::multiset<std::string> keys;
|
std::map<std::string, size_t> keys;
|
||||||
const Poco::XML::Node* pNode = findNode(key);
|
const Poco::XML::Node* pNode = findNode(key);
|
||||||
if (pNode)
|
if (pNode)
|
||||||
{
|
{
|
||||||
@ -276,12 +276,12 @@ void XMLConfiguration::enumerate(const std::string& key, Keys& range) const
|
|||||||
if (pChild->nodeType() == Poco::XML::Node::ELEMENT_NODE)
|
if (pChild->nodeType() == Poco::XML::Node::ELEMENT_NODE)
|
||||||
{
|
{
|
||||||
const std::string& nodeName = pChild->nodeName();
|
const std::string& nodeName = pChild->nodeName();
|
||||||
int n = (int) keys.count(nodeName);
|
size_t& count = keys[nodeName];
|
||||||
if (n)
|
if (count)
|
||||||
range.push_back(nodeName + "[" + NumberFormatter::format(n) + "]");
|
range.push_back(nodeName + "[" + NumberFormatter::format(count) + "]");
|
||||||
else
|
else
|
||||||
range.push_back(nodeName);
|
range.push_back(nodeName);
|
||||||
keys.insert(nodeName);
|
++count;
|
||||||
}
|
}
|
||||||
pChild = pChild->nextSibling();
|
pChild = pChild->nextSibling();
|
||||||
}
|
}
|
||||||
|
@ -300,6 +300,27 @@ void XMLConfigurationTest::testLoadEmpty()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XMLConfigurationTest::testManyKeys()
|
||||||
|
{
|
||||||
|
std::ostringstream ostr;
|
||||||
|
ostr << "<config>\n";
|
||||||
|
const size_t count = 200000;
|
||||||
|
for (size_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
ostr << "<element>" << i << "</element>\n";
|
||||||
|
}
|
||||||
|
ostr << "</config>\n";
|
||||||
|
|
||||||
|
std::istringstream istr(ostr.str());
|
||||||
|
AutoPtr<XMLConfiguration> pConf = new XMLConfiguration(istr);
|
||||||
|
|
||||||
|
AbstractConfiguration::Keys all_elements;
|
||||||
|
pConf->keys("", all_elements);
|
||||||
|
|
||||||
|
assertTrue(all_elements.size() == count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLConfigurationTest::setUp()
|
void XMLConfigurationTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -322,6 +343,7 @@ CppUnit::Test* XMLConfigurationTest::suite()
|
|||||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testSaveEmpty);
|
CppUnit_addTest(pSuite, XMLConfigurationTest, testSaveEmpty);
|
||||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testFromScratch);
|
CppUnit_addTest(pSuite, XMLConfigurationTest, testFromScratch);
|
||||||
CppUnit_addTest(pSuite, XMLConfigurationTest, testLoadEmpty);
|
CppUnit_addTest(pSuite, XMLConfigurationTest, testLoadEmpty);
|
||||||
|
CppUnit_addTest(pSuite, XMLConfigurationTest, testManyKeys);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
void testSaveEmpty();
|
void testSaveEmpty();
|
||||||
void testFromScratch();
|
void testFromScratch();
|
||||||
void testLoadEmpty();
|
void testLoadEmpty();
|
||||||
|
void testManyKeys();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user