Repository navigation
Share code that two places wrote twice, in the Core internals and the two pumps - #304
Merged
Merged
Conversation
… two pumps No public API changes. Every change is internal, or a message or a name that no caller reads. - The Channel and Dataflow pumps share two helpers in Core: the one that disposes an enumerator that will not be read, and the ones that link a caller's token to a stream's stall expiry and recognize an expiry that the caller did not cancel. Each pump keeps its own try/catch and its per-row loops. - DirectStream and StallStream take the stall timeout exception and the "enumerated only once" exception from one place, with the same texts. - A chunk of a stream is released with a using: the lease is IDisposable (Dispose releases it, as Release does). - ChunkChain.Dispose asks Used for the rows of a chunk, as the copy out does. ChunkSizes checks its power-of-two bounds with one helper. PooledBuffer.From builds its config in one place. - The "matches none of the parameters" exception has one text for a command and for a query (the words before the declared names stay as they were). - ExpressiveCommandBase asks for the declared text names in one place, and builds the refusal of ExecuteAsync with captures in one place. - ExpressiveDbCommand passes a connection function straight to its base, as its siblings do. A null function now names the parameter connFactory in the ArgumentNullException (it named the adapter's parameter, factory). - The procedure schema code: the table that GetSchema returns is disposed, the "rows from more than one schema" scan and the collection name are shared by the names and the metadata, the two one-line wrappers around the row reader are gone, one helper reads an integer that may not be one, and the exception filter that mixes `is` and `&&` is parenthesized. - MappedDbQuery builds its changed copies in one method; the two view executors share the canceled-token answer; the command view makes one query core instead of two. - The 776 of the SQL Server procedure lookup is a named constant with the arithmetic. Cost: nothing per row or per call. The new shared calls sit on the setup of a pass (the link), on a throw path (the exceptions) or on a dispose. The stream iterator that releases a chunk with a using may carry one more struct in its state machine (once per stream, not per chunk). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Internal refactor from a look at the code added since rc.16: places that wrote the same thing twice now share it. The net is 11 source lines removed (206 added, 217 deleted, 18 files): small, because the helpers add lines and the largest candidate was left out (below).
No public API changes. Every change is internal, or a message or a name that no caller reads.
disposes an enumerator that will not be read, and the ones that link a
caller's token to a stream's stall expiry and recognize an expiry that
the caller did not cancel. Each pump keeps its own try/catch and its
per-row loops.
"enumerated only once" exception from one place, with the same texts.
(Dispose releases it, as Release does).
does. ChunkSizes checks its power-of-two bounds with one helper.
PooledBuffer.From builds its config in one place.
command and for a query (the words before the declared names stay as
they were).
builds the refusal of ExecuteAsync with captures in one place.
as its siblings do. A null function now names the parameter
connFactory in the ArgumentNullException (it named the adapter's
parameter, factory).
disposed, the "rows from more than one schema" scan and the collection
name are shared by the names and the metadata, the two one-line
wrappers around the row reader are gone, one helper reads an integer
that may not be one, and the exception filter that mixes
isand&&is parenthesized.
executors share the canceled-token answer; the command view makes one
query core instead of two.
arithmetic.
Cost: nothing per row or per call. The new shared calls sit on the setup
of a pass (the link), on a throw path (the exceptions) or on a dispose.
The stream iterator that releases a chunk with a using may carry one more
struct in its state machine (once per stream, not per chunk).
Two behavior notes (neither is a code path anyone depends on)
ExpressiveDbCommandnow reportsArgumentNullException.ParamNameasconnFactory(it was the adapter'sfactory).Left out
Reading the procedure's parameter names and its metadata with one
GetSchemacall: the names come through the protected virtualGetProcedureParameterNamesAsync(an extension point; the SQL Server package reads names with its own query), so sharing the table needs hidden per-command state or a new virtual. That is a design change, not a refactor.Checks
No benchmark was run: the shared calls are on setup, throw and dispose paths only, as the cost line says.
Release 15,990 and Debug 15,969 tests pass (16 skipped), Generator tests 189, the package consumer tests with the generator on and off (net11.0 and net472), 0 build warnings on every target framework, 255 sample checks, VS MSBuild 0 errors,
dotnet formatstyle and analyzers clean on all 28 checks, DocFX 0 warnings, the style scan clean. No test was changed.🤖 Generated with Claude Code