1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

refactor: remove goto statements from replica.cc (#2633)

* remove goto statements from replica.cc
This commit is contained in:
Kostas Kyrimis 2024-02-21 13:02:36 +02:00 committed by GitHub
parent f32156788e
commit 52548fe3a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1001,9 +1001,14 @@ error_code Replica::ParseReplicationHeader(base::IoBuf* io_buf, PSyncResponse* d
std::string_view header;
bool valid = false;
auto bad_header = [str]() {
LOG(ERROR) << "Bad replication header: " << str;
return std::make_error_code(std::errc::illegal_byte_sequence);
};
// non-empty lines
if (str[0] != '+') {
goto bad_header;
return bad_header();
}
header = str.substr(1);
@ -1021,7 +1026,7 @@ error_code Replica::ParseReplicationHeader(base::IoBuf* io_buf, PSyncResponse* d
}
if (!valid)
goto bad_header;
return bad_header();
io_buf->ConsumeInput(str.size() + 2);
RETURN_ON_ERR(ReadLine(io_buf, &str)); // Read the next line parsed below.
@ -1031,7 +1036,7 @@ error_code Replica::ParseReplicationHeader(base::IoBuf* io_buf, PSyncResponse* d
DCHECK(!str.empty());
if (str[0] != '$') {
goto bad_header;
return bad_header();
}
std::string_view token = str.substr(1);
@ -1057,10 +1062,6 @@ error_code Replica::ParseReplicationHeader(base::IoBuf* io_buf, PSyncResponse* d
}
return error_code{};
bad_header:
LOG(ERROR) << "Bad replication header: " << str;
return std::make_error_code(std::errc::illegal_byte_sequence);
}
Replica::Info Replica::GetInfo() const {