Skip to content

Commit

Permalink
Straightforward boolean write (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry authored Feb 6, 2025
1 parent dc9cfb8 commit 538d6fe
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions include/glaze/json/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,14 @@ namespace glz
++ix;
}
else {
// branchless dumping of `true` or `false`
static constexpr uint64_t false_v = 435728179558;
static constexpr uint64_t if_true_v = 434025983730;

const uint64_t state = false_v - (value * if_true_v);
std::memcpy(&b[ix], &state, 8);
ix += 5 - value;
if (value) {
std::memcpy(&b[ix], "true", 4);
ix += 4;
}
else {
std::memcpy(&b[ix], "false", 5);
ix += 5;
}
}
}
};
Expand Down

0 comments on commit 538d6fe

Please sign in to comment.