refactor(core, protocol): extract memory diff helper and add clarity comments - #163
Merged
Conversation
…comments extract `adjust_memory` helper in `ConcurrentKeyspace` to replace four copies of the signed-diff atomic update pattern in set, incr_by, incr_by_float, and append. add inline comments: - keyspace.rs: note that Value::String clone is a cheap Bytes refcount increment - command.rs: explain why command_name() uses an explicit match instead of a derive macro (the string mappings are the thing worth seeing at a glance)
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
…comments (#163) extract `adjust_memory` helper in `ConcurrentKeyspace` to replace four copies of the signed-diff atomic update pattern in set, incr_by, incr_by_float, and append. add inline comments: - keyspace.rs: note that Value::String clone is a cheap Bytes refcount increment - command.rs: explain why command_name() uses an explicit match instead of a derive macro (the string mappings are the thing worth seeing at a glance)
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
this pass targets two areas flagged in a readability review of
emberkv-coreandember-protocol.ConcurrentKeyspace— memory diff helperthe signed-diff atomic update pattern appeared four times in
set,incr_by,incr_by_float, andappend:extracted into
fn adjust_memory(&self, old_size: usize, new_size: usize). no logic change — same atomics, same ordering, same behavior ondiff == 0(no-op).keyspace.rs— clone commentget()returnsOk(Some(e.value.clone()))where the value isValue::String(Bytes). added a brief inline note that this is a cheap refcount increment so readers don't mistake it for a deep copy.command.rs—command_name()commentthe doc comment now explains why the match is explicit rather than derive-generated: a proc macro would obscure the string mappings, which are the thing most worth seeing at a glance when auditing command names.
what was tested
cargo build -p emberkv-core -p ember-protocol— cleancargo test -p emberkv-core -p ember-protocol— 330 tests pass, 0 failurescargo fmt --check -p emberkv-core -p ember-protocol— no formatting issues