Repository navigation
Avoid instantiating named_tuple_t<T> in HasDefaultVal via apply_to_fields - #126
Open
clockblocker wants to merge 2 commits into
Open
clockblocker wants to merge 2 commits into
clockblocker wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rfl::internal::HasDefaultVal<T>previously inherited fromHasDefaultVal<named_tuple_t<T>>for every aggregate structT, forcing instantiation ofremove_ptrs_nt<view_t<T>>and a full value-typerfl::NamedTuple<Field<...>...>just to inspect whether any field carriesrfl::DefaultVal.This PR:
bind_to_tuple(both C++20 and C++26, plusscripts/bind_to_tuple.py) intorfl::internal::apply_to_fields(T&, F&&)and implementsbind_to_tupleas a one-line wrapper around it.HasDefaultVal<T> : HasDefaultVal<named_tuple_t<T>>with unevaluateddecltype(apply_to_fields(std::declval<T&>(), HasDefaultValVisitor{})), unwrappingrfl::Fieldand recursing intorfl::Flatten(including pointer-wrappedFlattenused byTaggedUnionWrapper) with zeroTuple/NamedTuple/get_field_namesinstantiation and dropping thenamed_tuple_t.hppinclude fromhas_default_val_v.hpp.rfl::Rename,rfl::Field, single/nested/pointer/NamedTuplerfl::Flatten, non-flattened nested structs, non-default-constructible/move-only/const/C-array members, inheritance,std::array, C arrays, unions, non-aggregates, and directapply_to_fieldsusage.Zero public API changes.
Measured Impact (AppleClang 17, C++20, interleaved
user+sysCPU)has_default_val_v, 100 × 20-field structs,-fsyntax-only): 5.34s → 2.30s (−57.0%)rfl::json::readfront-end (30 × 20-field structs,-fsyntax-only): 6.92s → 6.63s (−4.2%)NamedTuplefoundation for futureParser_defaultcompile-time optimizations.Verification
-std=c++20 -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror) pass on all modified C++20 headers.609 / 609CTests pass (json,json_c_arrays_and_inheritance,generic,cli,env) under-Wall -Werror.