Skip to content

Commit 22c2873

Browse files
committed
Reserve vector capacity when populating vectors in conversion operators
1 parent 88d5365 commit 22c2873

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

highlevelilinstruction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ uint64_t HighLevelILIntegerList::operator[](size_t i) const
321321
HighLevelILIntegerList::operator vector<uint64_t>() const
322322
{
323323
vector<uint64_t> result;
324+
result.reserve(size());
324325
for (auto i : *this)
325326
result.push_back(i);
326327
return result;
@@ -375,6 +376,7 @@ size_t HighLevelILIndexList::operator[](size_t i) const
375376
HighLevelILIndexList::operator vector<size_t>() const
376377
{
377378
vector<size_t> result;
379+
result.reserve(size());
378380
for (auto i : *this)
379381
result.push_back(i);
380382
return result;
@@ -440,6 +442,7 @@ const HighLevelILInstruction HighLevelILInstructionList::operator[](size_t i) co
440442
HighLevelILInstructionList::operator vector<HighLevelILInstruction>() const
441443
{
442444
vector<HighLevelILInstruction> result;
445+
result.reserve(size());
443446
for (auto i : *this)
444447
result.push_back(i);
445448
return result;
@@ -498,6 +501,7 @@ const SSAVariable HighLevelILSSAVariableList::operator[](size_t i) const
498501
HighLevelILSSAVariableList::operator vector<SSAVariable>() const
499502
{
500503
vector<SSAVariable> result;
504+
result.reserve(size());
501505
for (auto i : *this)
502506
result.push_back(i);
503507
return result;
@@ -651,6 +655,7 @@ const HighLevelILOperand HighLevelILOperandList::operator[](size_t i) const
651655
HighLevelILOperandList::operator vector<HighLevelILOperand>() const
652656
{
653657
vector<HighLevelILOperand> result;
658+
result.reserve(size());
654659
for (auto i : *this)
655660
result.push_back(i);
656661
return result;

lowlevelilinstruction.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ uint64_t LowLevelILIntegerList::operator[](size_t i) const
644644
LowLevelILIntegerList::operator vector<uint64_t>() const
645645
{
646646
vector<uint64_t> result;
647+
result.reserve(size());
647648
for (auto i : *this)
648649
result.push_back(i);
649650
return result;
@@ -697,6 +698,7 @@ size_t LowLevelILIndexList::operator[](size_t i) const
697698
LowLevelILIndexList::operator vector<size_t>() const
698699
{
699700
vector<size_t> result;
701+
result.reserve(size());
700702
for (auto i : *this)
701703
result.push_back(i);
702704
return result;
@@ -812,6 +814,7 @@ const LowLevelILInstruction LowLevelILInstructionList::operator[](size_t i) cons
812814
LowLevelILInstructionList::operator vector<LowLevelILInstruction>() const
813815
{
814816
vector<LowLevelILInstruction> result;
817+
result.reserve(size());
815818
for (auto i : *this)
816819
result.push_back(i);
817820
return result;
@@ -866,6 +869,7 @@ const RegisterOrFlag LowLevelILRegisterOrFlagList::operator[](size_t i) const
866869
LowLevelILRegisterOrFlagList::operator vector<RegisterOrFlag>() const
867870
{
868871
vector<RegisterOrFlag> result;
872+
result.reserve(size());
869873
for (auto i : *this)
870874
result.push_back(i);
871875
return result;
@@ -924,6 +928,7 @@ const SSARegister LowLevelILSSARegisterList::operator[](size_t i) const
924928
LowLevelILSSARegisterList::operator vector<SSARegister>() const
925929
{
926930
vector<SSARegister> result;
931+
result.reserve(size());
927932
for (auto i : *this)
928933
result.push_back(i);
929934
return result;
@@ -982,6 +987,7 @@ const SSARegisterStack LowLevelILSSARegisterStackList::operator[](size_t i) cons
982987
LowLevelILSSARegisterStackList::operator vector<SSARegisterStack>() const
983988
{
984989
vector<SSARegisterStack> result;
990+
result.reserve(size());
985991
for (auto i : *this)
986992
result.push_back(i);
987993
return result;
@@ -1040,6 +1046,7 @@ const SSAFlag LowLevelILSSAFlagList::operator[](size_t i) const
10401046
LowLevelILSSAFlagList::operator vector<SSAFlag>() const
10411047
{
10421048
vector<SSAFlag> result;
1049+
result.reserve(size());
10431050
for (auto i : *this)
10441051
result.push_back(i);
10451052
return result;
@@ -1098,6 +1105,7 @@ const SSARegisterOrFlag LowLevelILSSARegisterOrFlagList::operator[](size_t i) co
10981105
LowLevelILSSARegisterOrFlagList::operator vector<SSARegisterOrFlag>() const
10991106
{
11001107
vector<SSARegisterOrFlag> result;
1108+
result.reserve(size());
11011109
for (auto i : *this)
11021110
result.push_back(i);
11031111
return result;
@@ -1360,6 +1368,7 @@ const LowLevelILOperand LowLevelILOperandList::operator[](size_t i) const
13601368
LowLevelILOperandList::operator vector<LowLevelILOperand>() const
13611369
{
13621370
vector<LowLevelILOperand> result;
1371+
result.reserve(size());
13631372
for (auto i : *this)
13641373
result.push_back(i);
13651374
return result;
@@ -3357,6 +3366,7 @@ ExprId LowLevelILFunction::CallStackAdjust(
33573366
ExprId dest, int64_t adjust, const map<uint32_t, int32_t>& regStackAdjust, const ILSourceLocation& loc)
33583367
{
33593368
vector<size_t> list;
3369+
list.reserve(regStackAdjust.size() * 2);
33603370
for (auto& i : regStackAdjust)
33613371
{
33623372
list.push_back(i.first);

mediumlevelilinstruction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ uint64_t MediumLevelILIntegerList::operator[](size_t i) const
434434
MediumLevelILIntegerList::operator vector<uint64_t>() const
435435
{
436436
vector<uint64_t> result;
437+
result.reserve(size());
437438
for (auto i : *this)
438439
result.push_back(i);
439440
return result;
@@ -488,6 +489,7 @@ size_t MediumLevelILIndexList::operator[](size_t i) const
488489
MediumLevelILIndexList::operator vector<size_t>() const
489490
{
490491
vector<size_t> result;
492+
result.reserve(size());
491493
for (auto i : *this)
492494
result.push_back(i);
493495
return result;
@@ -600,6 +602,7 @@ const Variable MediumLevelILVariableList::operator[](size_t i) const
600602
MediumLevelILVariableList::operator vector<Variable>() const
601603
{
602604
vector<Variable> result;
605+
result.reserve(size());
603606
for (auto i : *this)
604607
result.push_back(i);
605608
return result;
@@ -658,6 +661,7 @@ const SSAVariable MediumLevelILSSAVariableList::operator[](size_t i) const
658661
MediumLevelILSSAVariableList::operator vector<SSAVariable>() const
659662
{
660663
vector<SSAVariable> result;
664+
result.reserve(size());
661665
for (auto i : *this)
662666
result.push_back(i);
663667
return result;
@@ -716,6 +720,7 @@ const MediumLevelILInstruction MediumLevelILInstructionList::operator[](size_t i
716720
MediumLevelILInstructionList::operator vector<MediumLevelILInstruction>() const
717721
{
718722
vector<MediumLevelILInstruction> result;
723+
result.reserve(size());
719724
for (auto i : *this)
720725
result.push_back(i);
721726
return result;
@@ -898,6 +903,7 @@ const MediumLevelILOperand MediumLevelILOperandList::operator[](size_t i) const
898903
MediumLevelILOperandList::operator vector<MediumLevelILOperand>() const
899904
{
900905
vector<MediumLevelILOperand> result;
906+
result.reserve(size());
901907
for (auto i : *this)
902908
result.push_back(i);
903909
return result;

0 commit comments

Comments
 (0)