Skip to content

Commit de07dc2

Browse files
committed
Simplify REPE error handling, remove from state
1 parent dfdb2ea commit de07dc2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

include/glaze/json/read.hpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ namespace glz
234234
constexpr auto type = HashInfo.type;
235235
constexpr auto N = reflect<T>::size;
236236

237-
if constexpr (not bool(type)) {
238-
static_assert(false_v<T>, "invalid hash algorithm");
239-
}
237+
static_assert(bool(type), "invalid hash algorithm");
240238

241239
if constexpr (N == 1) {
242240
decode_index<Opts, T, 0>(value, ctx, it, end, selected_index...);
@@ -265,9 +263,19 @@ namespace glz
265263
return;
266264
}
267265
}
268-
269-
// We see better performance with function pointers than a glz::jump_table here.
270-
visit<N>([&]<size_t I>() { decode_index<Opts, T, I>(value, ctx, it, end, selected_index...); }, index);
266+
267+
if constexpr (N == 2) {
268+
if (index == 0) {
269+
decode_index<Opts, T, 0>(value, ctx, it, end, selected_index...);
270+
}
271+
else {
272+
decode_index<Opts, T, 1>(value, ctx, it, end, selected_index...);
273+
}
274+
}
275+
else {
276+
// We see better performance with function pointers than a glz::jump_table here.
277+
visit<N>([&]<size_t I>() { decode_index<Opts, T, I>(value, ctx, it, end, selected_index...); }, index);
278+
}
271279
}
272280
}
273281

include/glaze/rpc/repe/registry.hpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace glz::repe
2020
{
2121
repe::message& in;
2222
repe::message& out;
23-
error_t& error;
2423

2524
bool notify() const { return in.header.notify(); }
2625

@@ -49,8 +48,7 @@ namespace glz::repe
4948
auto& in = state.in;
5049
auto& out = state.out;
5150
out.header.id = in.header.id;
52-
if (state.error) {
53-
out.header.error = true;
51+
if (out.header.error) {
5452
out.header.query_length = out.query.size();
5553
out.header.body_length = out.body.size();
5654
out.header.length = sizeof(repe::header) + out.query.size() + out.body.size();
@@ -72,8 +70,7 @@ namespace glz::repe
7270
auto& in = state.in;
7371
auto& out = state.out;
7472
out.header.id = in.header.id;
75-
if (state.error) {
76-
out.header.error = true;
73+
if (out.header.error) {
7774
out.header.query_length = out.query.size();
7875
out.header.body_length = out.body.size();
7976
out.header.length = sizeof(repe::header) + out.query.size() + out.body.size();
@@ -468,8 +465,12 @@ namespace glz::repe
468465
void call(message& in, message& out)
469466
{
470467
if (auto it = methods.find(in.query); it != methods.end()) {
471-
static thread_local error_t error{};
472-
it->second(state{in, out, error}); // handle the body
468+
if (in.header.error) {
469+
out = in;
470+
}
471+
else {
472+
it->second(state{in, out}); // handle the body
473+
}
473474
}
474475
else {
475476
static constexpr error_code code = error_code::method_not_found;

0 commit comments

Comments
 (0)