libutil: add should emplace inside a ChunkedVector
This simplifies many call-sites where construction can take place automatically. Change-Id: I87f697d55375676345b388024eb8df900bf808de Co-authored-by: Tom Hubrecht <github@mail.hubrecht.ovh> Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
co-authored by
Tom Hubrecht
parent
d8b1bb5862
commit
5db71cfb3b
@@ -90,7 +90,7 @@ public:
|
||||
auto it = symbols.find(s);
|
||||
if (it != symbols.end()) return Symbol(it->second.second + 1);
|
||||
|
||||
const auto & [rawSym, idx] = store.add(std::string(s));
|
||||
const auto & [rawSym, idx] = store.add(s);
|
||||
symbols.emplace(rawSym, std::make_pair(&rawSym, idx));
|
||||
return Symbol(idx + 1);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ public:
|
||||
|
||||
uint32_t size() const { return size_; }
|
||||
|
||||
std::pair<T &, uint32_t> add(T value)
|
||||
template<typename... Args>
|
||||
std::pair<T &, uint32_t> add(Args &&... args)
|
||||
{
|
||||
const auto idx = size_++;
|
||||
auto & chunk = [&] () -> auto & {
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
return back;
|
||||
return addChunk();
|
||||
}();
|
||||
auto & result = chunk.emplace_back(std::move(value));
|
||||
auto & result = chunk.emplace_back(std::forward<Args>(args)...);
|
||||
return {result, idx};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user