Skip to content

Commit 85a3694

Browse files
committed
carch reserve
1 parent ee69c76 commit 85a3694

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sources/libcore/filesystem/archiveCarch.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cage-core/pointerRangeHolder.h>
1010
#include <cage-core/serialization.h> // bufferView
1111
#include <cage-core/stdHash.h>
12+
#include <cage-core/string.h>
1213

1314
namespace cage
1415
{
@@ -103,6 +104,7 @@ namespace cage
103104
src->seek(arch.listStart);
104105
const auto buff = src->read(arch.listSize);
105106
Deserializer des(buff);
107+
files.reserve(arch.filesCount);
106108
for (uint32 i = 0; i < arch.filesCount; i++)
107109
{
108110
String n;
@@ -116,6 +118,7 @@ namespace cage
116118
}
117119
(FileHeader &)files[n] = h;
118120
}
121+
dirs.reserve(arch.dirsCount);
119122
for (uint32 i = 0; i < arch.dirsCount; i++)
120123
{
121124
String n;
@@ -140,9 +143,10 @@ namespace cage
140143

141144
// prepare new list
142145
std::vector<std::pair<String, FileHeaderEx>> fs;
146+
fs.reserve(files.size());
143147
for (auto &it : files)
144148
fs.emplace_back(it.first, std::move(it.second));
145-
std::sort(fs.begin(), fs.end(), [](const auto &a, const auto &b) -> bool { return a.first < b.first; });
149+
std::sort(fs.begin(), fs.end(), [](const auto &a, const auto &b) -> bool { return StringComparatorFast()(a.first, b.first); });
146150

147151
// read previous content
148152
// this is inefficient and temporary solution
@@ -178,9 +182,10 @@ namespace cage
178182
}
179183
{
180184
std::vector<String> ds;
185+
ds.reserve(dirs.size());
181186
for (const auto &it : dirs)
182187
ds.push_back(it);
183-
std::sort(ds.begin(), ds.end());
188+
std::sort(ds.begin(), ds.end(), StringComparatorFast());
184189
for (const auto &it : ds)
185190
ser << it;
186191
}

0 commit comments

Comments
 (0)