Skip to content

fix(c++): use std::move to reduce a copy#843

Merged
yangxk1 merged 1 commit intoapache:mainfrom
SYaoJun:842_fix_status
Feb 10, 2026
Merged

fix(c++): use std::move to reduce a copy#843
yangxk1 merged 1 commit intoapache:mainfrom
SYaoJun:842_fix_status

Conversation

@SYaoJun
Copy link
Contributor

@SYaoJun SYaoJun commented Feb 7, 2026

Reason for this PR

I found a potential improvemnt spot in status.h. issue: #842

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR targets small C++ performance cleanups in Status construction in GraphAr’s C++ runtime, aligning with issue #842’s goal of reducing unnecessary string copies in status.h.

Changes:

  • Change Status(StatusCode, const std::string&) to take std::string by value and move into internal storage.
  • Simplify Status::OK() to return {}.
  • Adjust Status::FromArgs(...) to move the StringBuilder(...) result into the constructor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

template <typename... Args>
static Status FromArgs(StatusCode code, Args... args) {
return Status(code, util::StringBuilder(std::forward<Args>(args)...));
return Status(code, std::move(util::StringBuilder(std::forward<Args>(args)...)));
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

std::move on the temporary returned by util::StringBuilder(...) is counterproductive here: it forces materialization of the temporary and can inhibit copy elision into the by-value Status constructor parameter, potentially adding an extra move (and for SSO strings, possibly a copy). Passing the return value directly should be at least as efficient and keeps the intent clearer.

Suggested change
return Status(code, std::move(util::StringBuilder(std::forward<Args>(args)...)));
return Status(code, util::StringBuilder(std::forward<Args>(args)...));

Copilot uses AI. Check for mistakes.
inline static Status OK() { return {}; }

template <typename... Args>
static Status FromArgs(StatusCode code, Args... args) {
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

FromArgs takes its parameter pack by value (Args... args), which defeats the perfect-forwarding used by IOError/KeyError/... and can introduce extra copies of the formatting arguments. Consider changing it to Args&&... args and forwarding those into util::StringBuilder to preserve the callers’ value categories.

Suggested change
static Status FromArgs(StatusCode code, Args... args) {
static Status FromArgs(StatusCode code, Args&&... args) {

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

codecov-commenter commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.21%. Comparing base (7bad8ec) to head (770d4d2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #843   +/-   ##
=========================================
  Coverage     80.21%   80.21%           
  Complexity      615      615           
=========================================
  Files            93       93           
  Lines         10265    10265           
  Branches       1047     1049    +2     
=========================================
  Hits           8234     8234           
  Misses         1791     1791           
  Partials        240      240           
Flag Coverage Δ
cpp 71.52% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@SYaoJun
Copy link
Contributor Author

SYaoJun commented Feb 10, 2026

@yangxk1y could you please review my code

Copy link
Contributor

@yangxk1 yangxk1 left a comment

Choose a reason for hiding this comment

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

LGTM~

@yangxk1 yangxk1 merged commit a8a5710 into apache:main Feb 10, 2026
12 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