Skip to content

Commit ed58a32

Browse files
committed
core,server: Make json expression templatized
The json expression maker function is templatized so it can be used with both short lived and storable JSON values. The short lived variant is used within search family validation. Signed-off-by: Abhijat Malviya <[email protected]>
1 parent 03a0fdc commit ed58a32

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/core/json/json_object.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#pragma once
66

7+
#include <glog/logging.h>
8+
79
#include <version> // for __cpp_lib_to_chars macro.
810

911
// std::from_chars is available in C++17 if __cpp_lib_to_chars is defined.
@@ -90,10 +92,13 @@ std::optional<JsonType> ParseJsonUsingShardHeap(std::string_view input);
9092
// malloc.
9193
JsonType DeepCopyJSON(const JsonType* j);
9294

93-
inline auto MakeJsonPathExpr(std::string_view path, std::error_code& ec)
94-
-> jsoncons::jsonpath::jsonpath_expression<JsonType> {
95-
return jsoncons::jsonpath::make_expression<JsonType, std::allocator<char>>(
96-
jsoncons::allocator_set<JsonType::allocator_type, std::allocator<char>>(), path, ec);
95+
template <typename Json = JsonType>
96+
auto MakeJsonPathExpr(std::string_view path, std::error_code& ec)
97+
-> jsoncons::jsonpath::jsonpath_expression<Json> {
98+
using result_allocator_t = typename Json::allocator_type;
99+
using temp_allocator_t = std::allocator<char>;
100+
using allocator_set_t = jsoncons::allocator_set<result_allocator_t, temp_allocator_t>;
101+
return jsoncons::jsonpath::make_expression<Json, temp_allocator_t>(allocator_set_t(), path, ec);
97102
}
98103

99104
} // namespace dfly

src/server/search/search_family.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bool SendErrorIfOccurred(const ParseResult<T>& result, CmdArgParser* parser,
8181

8282
bool IsValidJsonPath(string_view path) {
8383
error_code ec;
84-
MakeJsonPathExpr(path, ec);
84+
MakeJsonPathExpr<ShortLivedJSON>(path, ec);
8585
return !ec;
8686
}
8787

0 commit comments

Comments
 (0)