Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-44491: [C++] Static Status draft #44493

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bkietz
Copy link
Member

@bkietz bkietz commented Oct 21, 2024

Rationale for this change

It'd be convenient to construct placeholder error Status cheaply.

What changes are included in this PR?

Added bool Status::State::is_static which causes copies to be shallow and skips destruction.

Are these changes tested?

Not yet. Also, the main consideration is probably benchmarks to make sure hot paths don't get much slower.

Are there any user-facing changes?

I don't think we want this API to be public

Copy link

⚠️ GitHub issue #44491 has been automatically assigned in GitHub to PR creator.

Comment on lines +377 to +378
if (ARROW_PREDICT_TRUE(state_ == NULL)) return;
if (ARROW_PREDICT_FALSE(state_->is_static)) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably better to have a single condition here to make it obvious that the rest of the function is the cold code:

if (ARROW_PREDICT_TRUE(state_ == NULL || state_->is_static)) return;

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that this is more obvious for human readers, but I think the priority here is to make it obvious to the compiler that the hottest condition is state_ == NULL, independent of any other consideration

private:
struct State {
StatusCode code;
std::string msg;
std::shared_ptr<StatusDetail> detail;
bool is_static = false;
};
// OK status has a `NULL` state_. Otherwise, `state_` points to
// a `State` structure containing the error code and message(s)
State* state_;

void DeleteState() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Put noexcept here as well for consistency with ~Status() noexcept.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants