Replace std::bind with lambdas in eetf/ei.hpp#2646
Merged
Conversation
Every ei_* wrapper in the EETF decode/encode helpers used std::bind(ei_func, _1, _2, trailing...) passed to decode_impl/encode_impl. Each is a trailing-argument bind that a lambda expresses more clearly and inlines more reliably -- these helpers are all GLZ_ALWAYS_INLINE hot paths, and std::bind routes through an opaque std::invoke wrapper that decay-copies its bound args. Convert all 23 sites to lambdas and drop the now-unused 'using namespace std::placeholders;' from each function. Pure refactor, no behavioral change: decode_impl invokes the functor once as func(const char*, int*); encode_impl invokes it twice (nullptr sizing pass, then the real buffer) as func(char*, int*); the bound trailing arguments are passed through unchanged.
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
Replaces every
std::bindcall site ininclude/glaze/eetf/ei.hppwith an equivalent lambda. This is a pure refactor with no behavioral change.The EETF decode/encode helpers wrapped the C
ei_*functions withstd::bind(ei_func, _1, _2, trailing_args...)and passed the result todetail::decode_impl/detail::encode_impl. Each is a textbook trailing-argument bind, which a lambda expresses more clearly and compiles better.Why lambdas here
std::bindreturns an opaque call wrapper routed throughstd::invoke; compilers inline through it far less reliably than a lambda, especially in Debug. These helpers are allGLZ_ALWAYS_INLINEhot paths, so the codegen difference is real.std::binddecay-copies each bound argument into the wrapper; a[&]capture avoids that._1/_2placeholders and the per-functionusing namespace std::placeholders;. The fixed-signature lambda also makes theei_*call's argument list explicit and would be a compile error on a signature mismatch, wherebindwould silently swallow it.std::bind").Scope
std::bindsites converted (10 decode, 13 encode); 8 now-unusedusing namespace std::placeholders;lines removed.decode_implinvokes the functor once asfunc(const char*, int*);encode_implinvokes it twice (anullptrsizing pass then the real buffer) asfunc(char*, int*). The bound trailing arguments are passed through unchanged.ei.hppdid not directly include<functional>.Verification
clang++ -std=c++23 -fsyntax-only -Wall -Wextra) via a harness that instantiates both the decode path (read_term) and the encode path (write_term) over a struct exercising bool / int / double / long long / unsigned long long / string / atom / vector / map (map header +encode_atom_lenkeys) / binary / tuple. Clean.clang-linux-erlangandgcc-erlangjobs, which link againsterl_interfaceand exercise these paths.