Skip to content

Commit cfe3eae

Browse files
committed
VM, Utils: using reserve() for insert time optimization
1 parent ef0bea0 commit cfe3eae

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/IP_Edit.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ IP_Edit::IP_Edit(QWidget* parent) : QFrame(parent)
148148
p3->setMaximumWidth(width);
149149
p4->setMaximumWidth(width);
150150

151+
lines.reserve(4);
151152
lines.append(p1);
152153
lines.append(p2);
153154
lines.append(p3);

src/Utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ QList<QString> Get_Templates_List()
407407
}
408408

409409
// OK. In Template Lists Only Unique Values
410+
all_templates.reserve(sys_templates_list.count() + user_templates_list.count());
410411
for (int ix = 0; ix < sys_templates_list.count(); ++ix)
411412
all_templates.append(sys_templates_list[ix].absoluteFilePath());
412413

src/VM.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Virtual_Machine::Virtual_Machine(const Virtual_Machine& vm)
164164
this->Use_Redirections = vm.Get_Use_Redirections();
165165

166166
this->Network_Cards.clear();
167+
this->Network_Cards.reserve(vm.Get_Network_Cards_Count());
167168
for (int nx = 0; nx < vm.Get_Network_Cards_Count(); nx++) {
168169
VM_Net_Card n_card = vm.Get_Network_Card(nx);
169170

@@ -175,6 +176,7 @@ Virtual_Machine::Virtual_Machine(const Virtual_Machine& vm)
175176
this->Network_Cards_Native = vm.Get_Network_Cards_Native();
176177

177178
this->Network_Redirections.clear();
179+
this->Network_Redirections.reserve(vm.Get_Network_Redirections_Count());
178180
for (int rx = 0; rx < vm.Get_Network_Redirections_Count(); rx++) {
179181
VM_Redirection n_redir = vm.Get_Network_Redirection(rx);
180182

@@ -190,6 +192,7 @@ Virtual_Machine::Virtual_Machine(const Virtual_Machine& vm)
190192

191193
// USB
192194
this->USB_Ports.clear();
195+
this->USB_Ports.reserve(vm.Get_USB_Ports().count());
193196
for (int ux = 0; ux < vm.Get_USB_Ports().count(); ++ux) {
194197
this->USB_Ports.append(VM_USB(vm.Get_USB_Ports()[ux]));
195198
}
@@ -727,6 +730,7 @@ Virtual_Machine& Virtual_Machine::operator=(const Virtual_Machine& vm)
727730
this->Use_Redirections = vm.Get_Use_Redirections();
728731

729732
this->Network_Cards.clear();
733+
this->Network_Cards.reserve(vm.Get_Network_Cards_Count());
730734
for (int nx = 0; nx < vm.Get_Network_Cards_Count(); nx++) {
731735
VM_Net_Card n_card = vm.Get_Network_Card(nx);
732736

@@ -738,6 +742,7 @@ Virtual_Machine& Virtual_Machine::operator=(const Virtual_Machine& vm)
738742
this->Network_Cards_Native = vm.Get_Network_Cards_Native();
739743

740744
this->Network_Redirections.clear();
745+
this->Network_Redirections.reserve(vm.Get_Network_Redirections_Count());
741746
for (int rx = 0; rx < vm.Get_Network_Redirections_Count(); rx++) {
742747
VM_Redirection n_redir = vm.Get_Network_Redirection(rx);
743748

@@ -752,6 +757,7 @@ Virtual_Machine& Virtual_Machine::operator=(const Virtual_Machine& vm)
752757
this->Parallel_Ports = vm.Get_Parallel_Ports();
753758

754759
this->USB_Ports.clear();
760+
this->USB_Ports.reserve(vm.Get_USB_Ports().count());
755761
for (int ux = 0; ux < vm.Get_USB_Ports().count(); ++ux) {
756762
this->USB_Ports.append(VM_USB(vm.Get_USB_Ports()[ux]));
757763
}
@@ -8595,6 +8601,7 @@ void Virtual_Machine::Set_Snapshots(const QList<VM_Snapshot>& list)
85958601
{
85968602
Snapshots.clear();
85978603

8604+
Snapshots.reserve(list.count());
85988605
for (int sx = 0; sx < list.count(); ++sx) {
85998606
Snapshots.append(VM_Snapshot(list[sx]));
86008607
}
@@ -8645,6 +8652,7 @@ void Virtual_Machine::Set_Storage_Devices_List(
86458652
{
86468653
Storage_Devices.clear();
86478654

8655+
Storage_Devices.reserve(list.count());
86488656
for (int ix = 0; ix < list.count(); ++ix) {
86498657
Storage_Devices.append(VM_Native_Storage_Device(list[ix]));
86508658
}
@@ -8655,6 +8663,7 @@ void Virtual_Machine::Set_Shared_Folders_List(
86558663
{
86568664
Shared_Folders.clear();
86578665

8666+
Shared_Folders.reserve(list.count());
86588667
for (int ix = 0; ix < list.count(); ++ix) {
86598668
Shared_Folders.append(VM_Shared_Folder(list[ix]));
86608669
}
@@ -9068,6 +9077,7 @@ void Virtual_Machine::Set_USB_Ports(const QList<VM_USB>& list)
90689077
{
90699078
USB_Ports.clear();
90709079

9080+
USB_Ports.reserve(list.count());
90719081
for (int ix = 0; ix < list.count(); ++ix) {
90729082
USB_Ports.append(VM_USB(list[ix]));
90739083
}

src/VM_Wizard_Window.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ bool VM_Wizard_Window::Load_OS_Templates()
408408
{
409409
QList<QString> tmp_list = Get_Templates_List();
410410

411+
OS_Templates_List.reserve(tmp_list.count());
411412
for (int ax = 0; ax < tmp_list.count(); ++ax) {
412413
OS_Templates_List.append(QFileInfo(tmp_list[ax]));
413414
}

0 commit comments

Comments
 (0)