Move removeIndex's result instead of copying (#1516)

Currently removeIndex copies the removed value into removed and then
destructs the original, which can cause significant performance overhead.

Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
This commit is contained in:
jedav 2024-09-09 19:53:56 -07:00 committed by GitHub
parent 8d1ea7054f
commit fdb529bd06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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) {