Skip to content

forward mapped value in object::insert_or_assign assign branch - #1186

Merged
grisumbras merged 3 commits into
boostorg:developfrom
Ramya-9353:insert-or-assign-move
Aug 19, 2026
Merged

forward mapped value in object::insert_or_assign assign branch#1186
grisumbras merged 3 commits into
boostorg:developfrom
Ramya-9353:insert-or-assign-move

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: insert_or_assign(key, std::move(v)) on an existing key, with v on the object's own resource, deep-copies v and leaves it intact instead of moving it. For a 100-element array the assign branch runs 101 allocations and the source array is still populated afterwards.
Cause: the assign branch casts the mapped value to M rather than M&&, so for an rvalue argument it selects value(value const&), which allocates a copy on the source's storage before the copy into sp_. The insert branch one line above already forwards with M&&.
Fix: cast to M&& to match the insert branch. The stored value is unchanged; the redundant copy and the ignored move go away.

@cppalliance-bot

cppalliance-bot commented Aug 15, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1186.json.prtest2.cppalliance.org/libs/json/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-08-19 06:03:58 UTC

@cppalliance-bot

cppalliance-bot commented Aug 15, 2026

Copy link
Copy Markdown

GCOVR code coverage report https://1186.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1186.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1186.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-08-19 06:37:59 UTC

@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.71%. Comparing base (e2f976c) to head (08e993d).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1186   +/-   ##
========================================
  Coverage    93.71%   93.71%           
========================================
  Files           85       85           
  Lines         8971     8980    +9     
========================================
+ Hits          8407     8416    +9     
  Misses         564      564           
Files with missing lines Coverage Δ
include/boost/json/impl/object.hpp 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2f976c...08e993d. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cppalliance-bot

Copy link
Copy Markdown

@grisumbras

Copy link
Copy Markdown
Member

Ouch. Thanks for catching this.

Comment thread test/object.cpp Outdated
@cppalliance-bot

Copy link
Copy Markdown

Comment thread test/object.cpp Outdated
@cppalliance-bot

Copy link
Copy Markdown

@grisumbras
grisumbras merged commit df2c791 into boostorg:develop Aug 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants