Skip to content

improve: FrozenDictionary command dispatch map in WindowsNodeClient#205

Merged
shanselman merged 2 commits intomasterfrom
fix/pr197-event-test
Apr 23, 2026
Merged

improve: FrozenDictionary command dispatch map in WindowsNodeClient#205
shanselman merged 2 commits intomasterfrom
fix/pr197-event-test

Conversation

@shanselman
Copy link
Copy Markdown
Collaborator

O(1) FrozenDictionary lookup replacing O(n) FirstOrDefault scans for node command dispatch. Based on Repo Assist PR #197 with additional event-path test coverage identified during rubber-duck review.

4 tests: request-path routing, unknown command, collision, and event-path dispatch.

All 774 tests pass.

github-actions Bot and others added 2 commits April 23, 2026 10:44
Replace O(n) linear capability scans with O(1) FrozenDictionary lookup.

- Add _commandMap field (FrozenDictionary<string, INodeCapability>)
- Add BuildCommandMap() to (re)build the map after each RegisterCapability call
- Replace both FirstOrDefault dispatch calls with _commandMap.GetValueOrDefault
- First-registered capability wins on command collision (preserves original semantics)
- Add 3 tests: routing, unknown command, first-registered-wins collision

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace two O(n) FirstOrDefault(c => c.CanHandle(command)) scans
with O(1) FrozenDictionary lookup. TryAdd preserves first-registered-
wins semantics. Map rebuilt on each RegisterCapability() call
(startup only, before ConnectAsync).

Add event-path dispatch test to cover HandleNodeInvokeEventAsync
in addition to the request-path tests.

Based on Repo Assist PR #197, with additional test coverage.
Closes #197
@shanselman shanselman merged commit 5a97268 into master Apr 23, 2026
14 checks passed
@shanselman shanselman deleted the fix/pr197-event-test branch April 23, 2026 17:54
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