Skip to content

optimize JsonWriter::validate #1172

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

Closed

Conversation

BillyDonahue
Copy link
Contributor

@BillyDonahue BillyDonahue commented May 12, 2020

Based on discussion started in #1171

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 93.85% when pulling 3b416b0 on BillyDonahue:validate_1171 into b8cb888 on open-source-parsers:master.

if (valid_keys.find(key) == valid_keys.end()) {
inv[key] = settings_[key];
}
static const auto& valid_keys = *new std::set<String>{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no sense making a fresh valid_keys set each time validate is called.
Everybody can share one.

if (invalid)
(*invalid)[std::move(key)] = *si;
else
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If invalid==nullptr, then the caller will only get a pass/fail result.
We might as well return as soon as we know the answer.

bool StreamWriterBuilder::validate(Json::Value* invalid) const {
Json::Value my_invalid;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This object is always a waste.
In the invalid==nullptr case, we populate this Value just to throw it away.
In the invalid!=nullptr case, we create it and never use it.

@BillyDonahue BillyDonahue requested a review from dota17 May 12, 2020 16:53
@BillyDonahue
Copy link
Contributor Author

Subsumed by PR #1171.

@BillyDonahue BillyDonahue deleted the validate_1171 branch May 12, 2020 23:20
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.

2 participants