Skip to content

refactor: ember-core unreachable removal and sorted_set optimization#122

Merged
kacy merged 1 commit intomainfrom
refactor/ember-core
Feb 14, 2026
Merged

refactor: ember-core unreachable removal and sorted_set optimization#122
kacy merged 1 commit intomainfrom
refactor/ember-core

Conversation

@kacy
Copy link
Copy Markdown
Owner

@kacy kacy commented Feb 14, 2026

summary

  • replaces 3 unreachable!() calls in keyspace.rs with let-else patterns
    that return proper errors instead of panicking
  • replaces expect("verified above") double-lookup pattern in list_pop
    with a single get_mut + let-else
  • reduces member cloning in sorted_set::add_with_flags from 2 clones to 1
    by reordering the scores/tree inserts (clone into scores, move into tree)

what was tested

  • cargo test -p emberkv-core — all 329 tests pass
  • cargo check -p emberkv-core

design considerations

the let-else pattern is preferred over if let + unreachable!() because
it makes the code flow linear and eliminates dead branches. the sorted_set
reorder is safe because both collections are private — no external observer
can see them in an inconsistent intermediate state.

…ning

keyspace.rs:
- list_push: use let-else to destructure Value::List, capture len before
  touch() instead of re-matching after mutation
- list_pop: replace expect("verified above") + unreachable!() with
  let-else pattern that eliminates the double HashMap lookup
- hincrby: replace unreachable!() else branch with let-else that returns
  a proper error

sorted_set.rs:
- add_with_flags: reorder tree/scores inserts so the member is cloned
  once (into scores) then moved (into tree), instead of cloning twice
@kacy kacy merged commit ecffbc4 into main Feb 14, 2026
7 checks passed
@kacy kacy deleted the refactor/ember-core branch February 14, 2026 21:48
kacy added a commit that referenced this pull request Feb 19, 2026
…ning (#122)

keyspace.rs:
- list_push: use let-else to destructure Value::List, capture len before
  touch() instead of re-matching after mutation
- list_pop: replace expect("verified above") + unreachable!() with
  let-else pattern that eliminates the double HashMap lookup
- hincrby: replace unreachable!() else branch with let-else that returns
  a proper error

sorted_set.rs:
- add_with_flags: reorder tree/scores inserts so the member is cloned
  once (into scores) then moved (into tree), instead of cloning twice
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