Refactor: DRY up validation, split extension into per-class files#6
Merged
Refactor: DRY up validation, split extension into per-class files#6
Conversation
Extract shared inline helpers and macros to reduce duplication: - sv_check_string(): inline type validation (3 call sites) - sv_check_bounds(): inline overflow-safe bounds check (3 call sites) - sv_init_fields(): shared struct initialization (3 call sites) - SV_STRICT_SEARCH(): macro for strict Regexp-guard wrappers (4 functions) Net reduction: 39 insertions, 73 deletions.
Reorder file sections so each class's code is contiguous: 1. Shared infrastructure (struct, TypedData, validators, init helper) 2. StringView (internal helpers, construction, tiers 1-3, bang methods) 3. StringView::Strict (WouldAllocate, strict search guards) 4. StringView::Pool (struct, GC, alloc, grow, view, reset, backing) 5. Init Pure code motion — no functional changes.
Extract StringView::Strict and StringView::Pool into their own compilation units with a shared header: - string_view.h: structs, extern globals, SV_INLINE helpers, cross-file function declarations - string_view.c: core StringView implementation + Init_string_view - string_view_strict.c: WouldAllocate, strict search guards, Init_string_view_strict - string_view_pool.c: pool struct, GC, alloc/grow/view/reset, Init_string_view_pool Benchmarked before and after — no performance regression. All SV_INLINE helpers are fully inlined across compilation units (verified via nm).
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
sv_check_string,sv_check_bounds,sv_init_fields) and aSV_STRICT_SEARCHmacro to eliminate duplicated validation and strict search guard codepool_view,sv_initialize, andsv_reset(previouslyoff + lencould wrap on large inputs)string_view.cintostring_view.h,string_view.c,string_view_strict.c, andstring_view_pool.cfor cleaner class separationreset!)pool_memsizenow reports the cost of pre-allocated views for accurateObjectSpace.memsize_ofBenchmark verification
Full benchmark suite run before and after the split — all results within noise (±5%). No performance regression.
SV_INLINEhelpers confirmed fully inlined vianm(no symbols in binary).