Skip to content

src: copy-construct data when cloning threadsafe COW - #64859

Open
Archkon wants to merge 1 commit into
nodejs:mainfrom
Archkon:cow2
Open

src: copy-construct data when cloning threadsafe COW#64859
Archkon wants to merge 1 commit into
nodejs:mainfrom
Archkon:cow2

Conversation

@Archkon

@Archkon Archkon commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Initialize the cloned data directly while holding the source read lock, so payloads do not need to be default-constructible or copy-assignable.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jul 31, 2026
Initialize the cloned data directly while holding the source read lock,
so payloads do not need to be default-constructible or copy-assignable.

Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.16%. Comparing base (c8e2a82) to head (773b304).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64859   +/-   ##
=======================================
  Coverage   90.16%   90.16%           
=======================================
  Files         746      746           
  Lines      242760   242763    +3     
  Branches    45765    45769    +4     
=======================================
+ Hits       218875   218879    +4     
- Misses      15375    15389   +14     
+ Partials     8510     8495   -15     
Files with missing lines Coverage Δ
src/node_threadsafe_cow-inl.h 95.00% <100.00%> (+63.42%) ⬆️

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

const ThreadsafeCopyOnWrite<CopyConstructOnly> original(42);
auto copy = original;

EXPECT_EQ(copy.write()->value, 42);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional test improvement

The existing assertion proves cloning succeeded, but the test could additionally demonstrate COW independence:

TEST(ThreadsafeCopyOnWriteTest, CloneCopyConstructsData) {
  const ThreadsafeCopyOnWrite<CopyConstructOnly> original(42);
  auto copy = original;

  copy.write()->value = 43;

  EXPECT_EQ(original.read()->value, 42);
  EXPECT_EQ(copy.read()->value, 43);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants