Skip to content

Commit

Permalink
Move removeIndex's result instead of copying (#1516)
Browse files Browse the repository at this point in the history
Currently removeIndex copies the removed value into removed and then
destructs the original, which can cause significant performance overhead.

Co-authored-by: Jordan Bayles <[email protected]>
  • Loading branch information
jedav and baylesj authored Sep 10, 2024
1 parent 8d1ea70 commit fdb529b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
return false;
}
if (removed)
*removed = it->second;
*removed = std::move(it->second);
ArrayIndex oldSize = size();
// shift left all items left, into the place of the "removed"
for (ArrayIndex i = index; i < (oldSize - 1); ++i) {
Expand Down

0 comments on commit fdb529b

Please sign in to comment.