Skip to content

Commit 5ea324e

Browse files
committed
fix: use move instead of const &
Prevents possible copying of the 1st argument into the object
1 parent 8dabebd commit 5ea324e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/tree.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct CandidateObject {
3131
const size_t level = 0;
3232
const size_t index = 0;
3333

34-
CandidateObject(const CandidateString &data_, const size_t level_, const size_t index_) noexcept
35-
: data{ data_ }, level{ level_ }, index{ index_ } {}
34+
CandidateObject(CandidateString &&data_, const size_t level_, const size_t index_) noexcept
35+
: data{ move(data_) }, level{ level_ }, index{ index_ } {}
3636
};
3737

3838
template<typename T>
@@ -53,9 +53,15 @@ struct Tree {
5353

5454
/** 1st argument is a single object */
5555
void makeEntriesArray(const Napi::Object &jsTree, const size_t level, const size_t iEntry) {
56-
// get the current data
57-
const auto data = jsTree.Get(dataKey).ToString().Utf8Value();
58-
entriesArray.emplace_back(CandidateObject(data, level, iEntry));
56+
// finally emplace it back
57+
entriesArray.emplace_back(
58+
// then make the CandidateObject
59+
CandidateObject(
60+
jsTree.Get(dataKey).ToString().Utf8Value(),// first, get the current data
61+
level,
62+
iEntry)
63+
64+
);
5965

6066
// add children if any
6167
auto mayChildren = getChildren(jsTree, childrenKey);

0 commit comments

Comments
 (0)