op: Use std::vector's insert member function within vector variant of Add()
While looping here does work fine, it's mildly inefficient, particularly if the number of members being added is large, because it can result in multiple allocations over the period of the insertion, depending on how much extra memory push_back may allocate for successive elements. Instead, we can just tell the std::vector that we want to slap the whole contained sequence at the back of it with insert, which lets it allocate the whole memory block in one attempt.
This commit is contained in:
parent
6fd44e494c
commit
f6f5913b5f
1 changed files with 1 additions and 3 deletions
|
@ -115,9 +115,7 @@ void Op::Add(std::string string) {
|
|||
}
|
||||
|
||||
void Op::Add(const std::vector<Id>& ids) {
|
||||
for (Id op : ids) {
|
||||
Add(op);
|
||||
}
|
||||
operands.insert(operands.end(), ids.begin(), ids.end());
|
||||
}
|
||||
|
||||
u16 Op::WordCount() const {
|
||||
|
|
Loading…
Reference in a new issue