lingbin commented on a change in pull request #2969: Improve implementation of
Status
URL: https://github.com/apache/incubator-doris/pull/2969#discussion_r382885009
##########
File path: be/src/common/status.h
##########
@@ -17,114 +17,136 @@ namespace doris {
class Status {
public:
- Status(): _state(nullptr) {}
+ Status() : _state(nullptr) { }
~Status() noexcept { delete[] _state; }
- // copy c'tor makes copy of error detail so Status can be returned by value
- Status(const Status& s)
- : _state(s._state == nullptr ? nullptr : copy_state(s._state)) {
- }
+ // Here _state == nullptr(Status::OK) is the most common case, so use this
as
+ // a fast path. This check can avoid one function call in most cases,
because
+ // _copy_state() is not an inline function.
+ Status(const Status& s) : _state(s._state == nullptr ? nullptr :
_copy_state(s._state)) { }
// same as copy c'tor
Status& operator=(const Status& s) {
// The following condition catches both aliasing (when this == &s),
// and the common case where both s and *this are OK.
if (_state != s._state) {
delete[] _state;
- _state = (s._state == nullptr) ? nullptr : copy_state(s._state);
+ _state = (s._state == nullptr) ? nullptr : _copy_state(s._state);
}
return *this;
}
- // move c'tor
Status(Status&& s) noexcept : _state(s._state) {
s._state = nullptr;
}
- // move assign
Status& operator=(Status&& s) noexcept {
- std::swap(_state, s._state);
+ if (_state != s._state) {
Review comment:
Yes, it is ok to use a variable after `std::move()` it.
At least the compiler will not prevent anyone from using it this way.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]