From f6f5913b5fa2e3cda6157e50c8cd895445ec494e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 14 Mar 2019 03:12:55 -0400 Subject: [PATCH] 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. --- src/op.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/op.cpp b/src/op.cpp index 6629d9d..df6cd10 100644 --- a/src/op.cpp +++ b/src/op.cpp @@ -115,9 +115,7 @@ void Op::Add(std::string string) { } void Op::Add(const std::vector& ids) { - for (Id op : ids) { - Add(op); - } + operands.insert(operands.end(), ids.begin(), ids.end()); } u16 Op::WordCount() const {