Skip to content

refactor: deduplicate buffer operations#28

Merged
uael merged 1 commit intomainfrom
refactor/deduplicate-buffer-ops
Mar 9, 2026
Merged

refactor: deduplicate buffer operations#28
uael merged 1 commit intomainfrom
refactor/deduplicate-buffer-ops

Conversation

@uael
Copy link
Copy Markdown
Owner

@uael uael commented Mar 8, 2026

Summary

  • Extract 6 shared buffer-write operations (write_flat, patch_near, patch_list_header, write_bytes, alloc_segment, patch_segment_next) into free functions in buf.rs
  • Both Emitter and Region now delegate to shared implementations, eliminating ~200 lines of copy-pasted code
  • Cache deref_raw() outside tight loops in session methods to avoid redundant expose_provenance calls per iteration
  • Use with_capacity in Region::trim to avoid reallocations during compaction
  • Remove dead commented-out Emit<T> for Infallible impl

Test plan

  • All tests pass (cargo test)
  • All 183 tests pass under Miri (MIRIFLAGS="-Zmiri-permissive-provenance" cargo +nightly miri test)
  • Clippy clean (cargo xtask lint)
  • No-alloc build passes (cargo clippy -p nearest --no-default-features)

🤖 Generated with Claude Code

Extract shared buffer-write operations (write_flat, patch_near,
patch_list_header, write_bytes, alloc_segment, patch_segment_next)
into free functions in buf.rs. Both Emitter and Region now delegate
to these shared implementations, eliminating ~200 lines of
copy-pasted code.

Also:
- Cache deref_raw() outside tight loops in session.rs methods
  (re_splice_list, filter_list, reverse_list, sort_list, dedup_list)
  to avoid redundant expose_provenance calls per iteration
- Use with_capacity in Region::trim to avoid reallocations
- Remove dead commented-out Emit<T> for Infallible impl

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@uael uael merged commit 848fd9a into main Mar 9, 2026
7 checks passed
@uael uael deleted the refactor/deduplicate-buffer-ops branch March 9, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant