Skip to content

Commit 50a6d2f

Browse files
refactor: address comments
Signed-off-by: Stepan Bagritsevich <[email protected]>
1 parent e6ec9a2 commit 50a6d2f

File tree

6 files changed

+15
-25
lines changed

6 files changed

+15
-25
lines changed

src/core/string_or_view.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66

77
#include <string>
88
#include <string_view>
9+
#include <utility>
910
#include <variant>
1011

1112
namespace dfly {
1213

1314
class StringOrView {
1415
public:
1516
static StringOrView FromString(std::string s) {
16-
StringOrView sov;
17-
sov.val_ = std::move(s);
18-
return sov;
17+
return StringOrView{std::move(s)};
1918
}
2019

2120
static StringOrView FromView(std::string_view sv) {
22-
StringOrView sov;
23-
sov.val_ = sv;
24-
return sov;
21+
return StringOrView{sv};
2522
}
2623

2724
StringOrView() = default;
@@ -30,6 +27,11 @@ class StringOrView {
3027
StringOrView& operator=(const StringOrView& o) = default;
3128
StringOrView& operator=(StringOrView&& o) = default;
3229

30+
explicit StringOrView(std::string&& s) : val_(std::forward<std::string>(s)) {
31+
}
32+
explicit StringOrView(std::string_view sv) : val_(sv) {
33+
}
34+
3335
bool operator==(const StringOrView& o) const {
3436
return *this == o.view();
3537
}

src/facade/facade_types.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include <optional>
1111
#include <string>
1212
#include <string_view>
13+
#include <utility>
1314
#include <variant>
1415

1516
#include "base/iterator.h"
17+
#include "core/string_or_view.h"
1618
#include "facade/op_status.h"
1719

1820
namespace facade {
@@ -155,26 +157,26 @@ struct FacadeStats {
155157

156158
struct ErrorReply {
157159
explicit ErrorReply(std::string&& msg, std::string_view kind = {})
158-
: message{std::move(msg)}, kind{kind} {
160+
: message{std::forward<std::string>(msg)}, kind{kind} {
159161
}
160162
explicit ErrorReply(std::string_view msg, std::string_view kind = {}) : message{msg}, kind{kind} {
161163
}
162164
explicit ErrorReply(const char* msg,
163165
std::string_view kind = {}) // to resolve ambiguity of constructors above
164166
: message{std::string_view{msg}}, kind{kind} {
165167
}
166-
explicit ErrorReply(OpStatus status) : message{}, kind{}, status{status} {
168+
explicit ErrorReply(OpStatus status) : status{status} {
167169
}
168170

169171
bool HasStatus() const {
170172
return status.has_value();
171173
}
172174

173175
std::string_view ToSv() const {
174-
return std::visit(kToSV, message);
176+
return message.view();
175177
}
176178

177-
std::variant<std::string, std::string_view> message;
179+
dfly::StringOrView message;
178180
std::string_view kind;
179181
std::optional<OpStatus> status{std::nullopt};
180182
};

src/facade/reply_builder.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ void SinkReplyBuilder::SendError(ErrorReply error) {
140140
if (error.HasStatus())
141141
return SendError(*error.status);
142142

143-
SendErrorReplyMessage(error);
144-
}
145-
146-
void SinkReplyBuilder::SendErrorReplyMessage(const ErrorReply& error) {
147143
SendError(error.ToSv(), error.kind);
148144
}
149145

src/facade/reply_builder.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class SinkReplyBuilder {
7979
}
8080

8181
virtual void SendError(std::string_view str, std::string_view type = {}) = 0; // MC and Redis
82-
void SendError(ErrorReply error);
8382
virtual void SendError(OpStatus status);
83+
void SendError(ErrorReply error);
8484

8585
virtual void SendStored() = 0; // Reply for set commands.
8686
virtual void SendSetSkipped() = 0;
@@ -148,8 +148,6 @@ class SinkReplyBuilder {
148148
static void ResetThreadLocalStats();
149149

150150
protected:
151-
virtual void SendErrorReplyMessage(const ErrorReply& error);
152-
153151
void SendRaw(std::string_view str); // Sends raw without any formatting.
154152
void SendRawVec(absl::Span<const std::string_view> msg_vec);
155153

src/facade/reply_capture.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ void CapturingReplyBuilder::SendError(std::string_view str, std::string_view typ
2121
Capture(Error{str, type});
2222
}
2323

24-
void CapturingReplyBuilder::SendErrorReplyMessage(const ErrorReply& error) {
25-
SKIP_LESS(ReplyMode::ONLY_ERR);
26-
Capture(Error{error.ToSv(), error.kind});
27-
}
28-
2924
void CapturingReplyBuilder::SendMGetResponse(MGetResponse resp) {
3025
SKIP_LESS(ReplyMode::FULL);
3126
Capture(std::move(resp));

src/facade/reply_capture.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ class CapturingReplyBuilder : public RedisReplyBuilder {
9797
std::vector<Payload> arr;
9898
};
9999

100-
protected:
101-
void SendErrorReplyMessage(const ErrorReply& error) override;
102-
103100
private:
104101
// Send payload directly, bypassing external interface. For efficient passing between two
105102
// captures.

0 commit comments

Comments
 (0)