Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

more extractor#2274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
lemire wants to merge20 commits intomaster
base:master
Choose a base branch
Loading
fromlemire/extractor
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
20 commits
Select commitHold shift + click to select a range
bba2080
object::extract
the-moisrexSep 12, 2024
b4e7d71
Optimize object::extract's performance
the-moisrexSep 12, 2024
142c9a9
Remove unnecessary function call
the-moisrexSep 12, 2024
414c585
noexcept-friendlification of endpoints
the-moisrexSep 13, 2024
dfde6d5
sub
the-moisrexSep 13, 2024
bee5593
Add macro
the-moisrexSep 13, 2024
c343f69
Moving things around to fix msvc error
the-moisrexSep 13, 2024
a4e3e38
Fix msvc and clang and gcc error
the-moisrexSep 13, 2024
c8bde7c
Propagating errors
the-moisrexSep 13, 2024
b4d72ff
explicitly ignoring to fix clang
the-moisrexSep 14, 2024
949bc51
adding benchmark to extractor
lemireSep 21, 2024
677674d
update
lemireSep 21, 2024
f7bf592
Merge pull request #1 from simdjson/extractor_bench
the-moisrexSep 21, 2024
6f19ccb
value_iterator::on_field_raw to optimize object::extract
the-moisrexSep 21, 2024
d9545b2
value_iterator::on_field_raw noexcept
the-moisrexSep 21, 2024
fe6c540
MSVC Fix
the-moisrexSep 21, 2024
207b626
extractor PR with clangcl tweaks
lemireSep 21, 2024
cf86e30
Merge pull request #2 from simdjson/extractor_clangcl
the-moisrexSep 24, 2024
c6fbf5b
moving SIMDJSON_SUPPORTS_EXTRACT
lemireOct 10, 2024
a927fb0
bump
lemireOct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Propagating errors
  • Loading branch information
@the-moisrex
the-moisrex committedSep 13, 2024
commitc8bde7cff0b18e97f1e661a5880f800e451e0111
64 changes: 40 additions & 24 deletionsinclude/simdjson/generic/ondemand/object-inl.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,21 +19,27 @@ namespace ondemand {
#ifdef SIMDJSON_SUPPORTS_EXTRACT

template <endpoint ...Funcs>
simdjson_inlinevoid object::extract(Funcs&&... endpoints)
simdjson_inlineerror_code object::extract(Funcs&&... endpoints)
#ifndef _MSC_VER // msvc thinks noexcept is not the same in definition
noexcept((nothrow_endpoint<Funcs> && ...))
#endif
{
raw_json_string field_key;
error_code error = SUCCESS;
for(auto pair : *this) {
if (pair.key().get(field_key)) {
if (error = pair.key().get(field_key); error) {
break;
}
((field_key.unsafe_is_equal(endpoints.key()) ? (error = endpoints(pair.value())) == SUCCESS : true) && ...);
if (error) {
break;
}
((field_key.unsafe_is_equal(endpoints.key()) && (endpoints(pair.value()), true)), ...);
}
return error;
}

template <typename T> struct to {
template <typename T>
struct to {
private:
T *pointer;
std::string_view m_key;
Expand All@@ -53,9 +59,9 @@ template <typename T> struct to {
return m_key;
}

constexprvoid operator()(simdjson_result<value> val) noexcept(
[[nodiscard]]constexprerror_code operator()(simdjson_result<value> val) noexcept(
std::is_nothrow_assignable_v<T, simdjson_result<value>>) {
*pointer =val;
returnval.get<T>(*pointer);
}
};

Expand All@@ -74,56 +80,66 @@ struct to<Func> {

constexpr to(to const &) = default;
constexpr to(to &&) noexcept = default;
constexpr to &operator=(to const &) = default;
constexpr to &operator=(to &&) noexcept = default;
constexpr to&operator=(to const &) = default;
constexpr to&operator=(to &&) noexcept = default;
constexpr ~to() = default;

[[nodiscard]] constexpr std::string_view key() const noexcept {
return m_key;
}

constexprvoid operator()(simdjson_result<value> val) noexcept(
[[nodiscard]]constexprerror_code operator()(simdjson_result<value> val) noexcept(
std::is_nothrow_invocable_v<Func, simdjson_result<value>>) {
func(val);
if constexpr (std::is_invocable_r_v<error_code, Func, simdjson_result<value>>) {
return func(val);
} else {
static_cast<void>(func(val));
return SUCCESS;
}
}
};

template <typename Func>
requires(std::is_invocable_v<Func, simdjson_result<value>>)
to(std::string_view, Func &&) -> to<Func>;

template <typename T> to(std::string_view, T &) -> to<T>;
template <typename T>
to(std::string_view, T&) -> to<T>;

template <endpoint... Tos> struct sub {
template <endpoint... Tos>
struct sub {
private:
using tuple_type = std::tuple<Tos...>;
tuple_type tos;

public:
explicit constexpr sub(Tos &&...inp_tos) noexcept(
std::is_nothrow_constructible_v<tuple_type, Tos...>)
: tos{std::forward<Tos>(inp_tos)...} {}

// double templating to make perfect forwarding work
template <typename ...T>
requires ((std::same_as<T, Tos> && ...))
explicit constexpr sub(T&&...inp_tos) noexcept(std::is_nothrow_constructible_v<tuple_type, T...>)
: tos{std::forward<T>(inp_tos)...} {}

constexpr sub(sub const &) = default;
constexpr sub(sub &&) noexcept = default;
constexpr sub &operator=(sub const &) = default;
constexpr sub &operator=(sub &&) = default;
constexpr ~sub() = default;

constexpr void operator()(simdjson_result<value> val) noexcept(
(nothrow_endpoint<Tos> && ...)) {
[[nodiscard]] constexpr error_code operator()(simdjson_result<value> val) noexcept((nothrow_endpoint<Tos> && ...)) {
object obj;
if (val.get_object().get(obj)) {
return;
if (auto const err =val.get_object().get(obj); err) {
return err;
}
std::apply(
[&obj]<typename... T>(T &&...app_tos) {
obj.extract(std::forward<T>(app_tos)...);
},
tos);
return std::apply([&obj]<typename... T>(T &&...app_tos) {
return obj.extract(std::forward<T>(app_tos)...);
}, tos);
}
};

template <endpoint... Tos>
sub(Tos&&...) -> sub<Tos...>;

#endif


Expand Down
11 changes: 4 additions & 7 deletionsinclude/simdjson/generic/ondemand/object.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,16 +15,13 @@ namespace ondemand {
#define SIMDJSON_SUPPORTS_EXTRACT 1

template <typename T>
concept endpoint = std::is_invocable_v<T, simdjson_result<value>> &&
concept endpoint = std::is_invocable_r_v<error_code,T, simdjson_result<value>> &&
std::is_copy_constructible_v<T> && requires(T to) {
{
to.key()
} noexcept -> std::convertible_to<std::string_view>;
{ to.key() } noexcept -> std::convertible_to<std::string_view>;
};

template <typename T>
concept nothrow_endpoint =
endpoint<T> && std::is_nothrow_invocable_v<T, simdjson_result<value>>;
concept nothrow_endpoint = endpoint<T> && std::is_nothrow_invocable_r_v<error_code, T, simdjson_result<value>>;

#endif

Expand DownExpand Up@@ -88,7 +85,7 @@ class object {
* Funcs are invocables that take a simdjson_result<value> as input.
*/
template <endpoint ...Funcs>
simdjson_inlinevoid extract(Funcs&&... endpoints)
simdjson_inlineerror_code extract(Funcs&&... endpoints)
#ifndef _MSC_VER // msvc thinks noexcept is not the same in definition
noexcept((nothrow_endpoint<Funcs> && ...))
#endif
Expand Down
5 changes: 4 additions & 1 deletiontests/ondemand/ondemand_extract_tests.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ struct Car {
// }
//
// we can do this now:
obj.extract(
error =obj.extract(
to{"wheels", sub{
to{"front", car.wheels.front},
to{"back", car.wheels.back},
Expand All@@ -59,6 +59,9 @@ struct Car {
to{"year", [&car](auto val) {
car.year = val;
}});
if (error) {
return error;
}
return car;
}
};
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp