skyitachi commented on code in PR #1890:
URL: https://github.com/apache/kvrocks/pull/1890#discussion_r1391896003
##########
src/types/json.h:
##########
@@ -446,6 +451,54 @@ struct JsonValue {
return Status::OK();
}
+ template <typename T>
+ static inline T NumOpIncrBy(T origin, T value) {
+ return origin + value;
+ }
+
+ template <typename T>
+ static inline T NumOpMulBy(T origin, T value) {
+ return origin * value;
+ }
+
+ Status NumOp(std::string_view path, const JsonValue &number, NumOpEnum op,
JsonValue *result) {
+ Status status = Status::OK();
+ try {
+ jsoncons::jsonpath::json_replace(value, path, [&](const std::string &
/*path*/, jsoncons::json &origin) {
+ if (!status.IsOK()) {
+ return;
+ }
+ if (!origin.is_number()) {
+ result->value.push_back(jsoncons::json::null());
+ return;
+ }
+ if (number.value.is_double() || origin.is_double()) {
+ double v = 0;
+ if (op == NumOpEnum::Incr) {
+ v = NumOpIncrBy<double>(origin.as_double(),
number.value.as_double());
+ } else if (op == NumOpEnum::Mul) {
+ v = NumOpMulBy<double>(origin.as_double(),
number.value.as_double());
Review Comment:
you mean use `v = origin.as_double() + number.value.as_double()` directly?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]