refactor: keyspace helpers for expiry, collection cleanup, and error strings - #99
Merged
Conversation
extracted two private helpers for the mechanical expiry bookkeeping that was duplicated across 10+ methods: - decrement_expiry_if_set: replaces the if-nonzero-saturating-sub pattern in try_evict, del, unlink, rename, remove_if_expired - adjust_expiry_count: replaces the match-on-had/has-expiry pattern in set and restore
the "if empty, remove key + adjust memory/expiry; else adjust memory" pattern appeared identically in list_pop, zrem, hdel, and srem. extracted cleanup_after_remove() — each call site drops from 8-10 lines to a single call.
these two functions were identical except for a / 1000 divisor. extracted a shared remaining() helper that both delegate to.
the WRONGTYPE and OOM error strings were duplicated across WrongType, IncrError, and IncrFloatError Display impls. added WRONGTYPE_MSG and OOM_MSG constants so they can't drift if one is updated.
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
…strings (#99) * refactor: add expiry count helpers to keyspace extracted two private helpers for the mechanical expiry bookkeeping that was duplicated across 10+ methods: - decrement_expiry_if_set: replaces the if-nonzero-saturating-sub pattern in try_evict, del, unlink, rename, remove_if_expired - adjust_expiry_count: replaces the match-on-had/has-expiry pattern in set and restore * refactor: extract cleanup_after_remove helper the "if empty, remove key + adjust memory/expiry; else adjust memory" pattern appeared identically in list_pop, zrem, hdel, and srem. extracted cleanup_after_remove() — each call site drops from 8-10 lines to a single call. * refactor: consolidate remaining_secs/remaining_ms in time.rs these two functions were identical except for a / 1000 divisor. extracted a shared remaining() helper that both delegate to. * refactor: shared error message constants for WRONGTYPE and OOM the WRONGTYPE and OOM error strings were duplicated across WrongType, IncrError, and IncrFloatError Display impls. added WRONGTYPE_MSG and OOM_MSG constants so they can't drift if one is updated.
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
decrement_expiry_if_setandadjust_expiry_counthelpers to replace 10+ inline expiry bookkeeping patterns across keyspace methodscleanup_after_removeto consolidate the "if-empty-remove-key-else-adjust-memory" pattern shared by list_pop, zrem, hdel, and sremremaining_secs/remaining_msin time.rs into a sharedremaining()helperWRONGTYPE_MSGandOOM_MSGconstants to prevent error string drift across WrongType, IncrError, and IncrFloatErrorwhat was tested
cargo clippy -p emberkv-core -- -D warnings— cleancargo test -p emberkv-core— all 301 tests pass