Skip to content

Commit 24e31ae

Browse files
committed
Add vector space reservation whenever it is possible
1 parent b6ae5a0 commit 24e31ae

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Dictionary/Dictionary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ namespace Plugin {
198198

199199
std::vector<Exchange::IDictionary::PathEntry> pathentries;
200200

201+
_adminLock.Lock();
202+
pathentries.reserve(_dictionary.size());
203+
_adminLock.Unlock();
204+
201205
if ((path.empty() == true) || ((path.size() == 1) && (path[0] == Exchange::IDictionary::namespaceDelimiter))) {
202206

203207
_adminLock.Lock();

NetworkControl/NetworkControl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ namespace Plugin
337337
auto dns = request.Body<const Core::JSON::ArrayType<Core::JSON::String>>()->Elements();
338338

339339
if (dns.Count()) {
340-
std::vector<string> elements;
340+
std::vector<string> elements;
341+
elements.reserve(dns.Count());
341342
while (dns.Next() == true) {
342343
elements.push_back(dns.Current());
343344
}
@@ -362,6 +363,8 @@ namespace Plugin
362363

363364
if (network.Count()) {
364365
std::vector<Exchange::INetworkControl::NetworkInfo> elements;
366+
elements.reserve(network.Count());
367+
365368
while (network.Next() == true) {
366369
elements.push_back(network.Current());
367370
}

NetworkControl/NetworkControlImplementation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,8 @@ namespace Plugin
968968
DNS(servers);
969969

970970
std::vector<string> dnsList;
971+
dnsList.reserve(servers.size());
972+
971973
for (const Core::NodeId& entry : servers) {
972974

973975
dnsList.push_back(entry.HostAddress());
@@ -1437,6 +1439,8 @@ namespace Plugin
14371439

14381440
void Interfaces(std::vector<string>& interfaces) const
14391441
{
1442+
interfaces.reserve(_info.size());
1443+
14401444
for (const auto& info : _info) {
14411445
interfaces.push_back(info.first);
14421446
}

examples/OutOfProcessPlugin/OutOfProcessPlugin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ namespace Plugin {
111111
}
112112

113113
std::vector<string> _elements;
114+
_elements.reserve(updates);
115+
114116
for(uint32_t i = 0; i<updates; ++i) {
115117
string s("UserScripts_Updated_");
116118
s += std::to_string(i);

0 commit comments

Comments
 (0)