Optimize google::api::expr::Unparse by removing unnecessary construction and copy of SourceInfo.#1800
Merged
Merged
Conversation
8da1cfd to
79d135b
Compare
…ction and copy of `SourceInfo`. `const auto& var = ptr == nullptr ? ProtoMessage() : *ptr;` can call `ProtoMessage::ProtoMessage` constructor whenever `ptr` is null. But, due to how ternary operators behave compiler will copy `*ptr` even when `ptr` is not null. OTOH, `const auto& var = ptr == nullptr ? ProtoMessage::default_instance() : *ptr;` won't do the similar call because `ProtoMessage::default_instance()` already returns a const reference. - The subtle difference between ternary operator and if-else can be seen here: https://godbolt.org/z/bPvjjn6dP - The overall change is similar to this: https://godbolt.org/z/8Phd9nzEh PiperOrigin-RevId: 840528597
79d135b to
20671a0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimize
google::api::expr::Unparseby removing unnecessary construction and copy ofSourceInfo.const auto& var = ptr == nullptr ? ProtoMessage() : *ptr;can callProtoMessage::ProtoMessageconstructor wheneverptris null. But, due to how ternary operators behave compiler will copy*ptreven whenptris not null.OTOH,
const auto& var = ptr == nullptr ? ProtoMessage::default_instance() : *ptr;won't do the similar call becauseProtoMessage::default_instance()already returns a const reference.