Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using reserve for optimize inserts and minor fixes #723

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/arclite/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,10 @@ class Plugin
});
const auto error_log = std::make_shared<ErrorLog>();
size_t im = 0, nm = matched_indices.size();
std::vector<UInt32> indices;
indices.reserve(nm);
while (im < nm) {
std::vector<UInt32> indices;
indices.clear();
auto parent = archive->file_list[matched_indices[im]].parent;
while (im < nm && archive->file_list[matched_indices[im]].parent == parent)
indices.push_back(matched_indices[im++]);
Expand Down
2 changes: 1 addition & 1 deletion plugins/arclite/sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class SfxOptionsDialog: public Far::Dialog {
bool show() {
label(Far::get_msg(MSG_SFX_OPTIONS_DLG_PROFILE));
std::vector<std::wstring> profile_names;
profile_names.reserve(profiles.size());
profile_names.reserve(profiles.size() + 1);
for (unsigned i = 0; i < profiles.size(); i++) {
profile_names.push_back(profiles[i].name);
}
Expand Down
8 changes: 6 additions & 2 deletions plugins/arclite/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ class UpdateDialog: public Far::Dialog {
void populate_profile_list() {
DisableEvents de(*this);
std::vector<FarListItem> fl_items;
fl_items.reserve(profiles.size() + 1);
FarListItem fl_item{};
for (unsigned i = 0; i < profiles.size(); i++) {
fl_item.Text = profiles[i].name.c_str();
Expand Down Expand Up @@ -1280,7 +1281,7 @@ class UpdateDialog: public Far::Dialog {
old_ext = ArcAPI::formats().at(m_options.arc_type).default_extension();

std::vector<std::wstring> profile_names;
profile_names.reserve(profiles.size());
profile_names.reserve(profiles.size() + 1);
unsigned profile_idx = static_cast<unsigned>(profiles.size());
std::for_each(profiles.begin(), profiles.end(), [&] (const UpdateProfile& profile) {
profile_names.push_back(profile.name);
Expand Down Expand Up @@ -1345,6 +1346,7 @@ class UpdateDialog: public Far::Dialog {
return _wcsicmp(a_format.name.c_str(), b_format.name.c_str()) < 0;
});
std::vector<std::wstring> other_format_names;
other_format_names.reserve(other_formats.size());
unsigned other_format_index = 0;
bool found = false;
for (const auto& t : other_formats) {
Expand Down Expand Up @@ -1378,9 +1380,11 @@ class UpdateDialog: public Far::Dialog {
label(Far::get_msg(MSG_UPDATE_DLG_METHOD));
std::wstring method = m_options.method.empty() && m_options.arc_type == c_7z? c_methods[0].value : m_options.method;
std::vector<std::wstring> method_names;
const auto sizeMethods = ARRAYSIZE(c_methods) + ArcAPI::Count7zCodecs();
method_names.reserve(sizeMethods);
const auto& codecs = ArcAPI::codecs();
unsigned method_sel = 0;
for (unsigned i = 0; i < ARRAYSIZE(c_methods) + ArcAPI::Count7zCodecs(); ++i) {
for (unsigned i = 0; i < sizeMethods; ++i) {
std::wstring method_name = i < ARRAYSIZE(c_methods) ? c_methods[i].value : codecs[i - ARRAYSIZE(c_methods)].Name;
if (method == method_name)
method_sel = i;
Expand Down
Loading