Between discussion at #1137 and a few rounds of revision at #1159 we
arrived at an optimisation where tasks that are both heavily hit and
very likely to return in a completed state are checked for a status of
either RanToCompletion, Canceled or Faulted and a path is taken where
no await is needed for any of those.
The Canceled and Faulted tasks are returned immediately, allowing that
state to be passed to the caller.
However, these are exceptional cases, and if we just continued the
subsequent await would raise the appropriate exception. Checking for
all three cases instead of just RanToCompletion is optimising for those
execptional conditions at cost (in the form of a larger comparison
segment of code) to the more common cases of the task either being
completed or still running.
Simplify this back to a check just for RanToCompletion.
Skip attempting write when string is empty.
FirstCharToEscape was introduced for the async version and gives a
faster means to identify the first block before any escaping, so may as
well use it here too.
Conversely, WriteEscapedStringThroughBuffer was introduced to share
code between the sync and async versions, but later optimisations meant
it was no longer used by the async. Inline the code back again.
Create an easily-inlinable method that accesses the array used
by Enumerable.Empty (and hence not just shared within this project
but likely with the client assembly or other libraries it uses)
and use it anywhere a zero-element array is used, reducing allocations.
* Remove unnecessary ToArray call.
* Remove Value property.
One use compares with null, so cast to T is a waste.
This leaves just one other use, so it can be inlined.
* Remove _dontFallbackFirst
Is always true. Remove it and branches for it being false.
* Don't use Expression.Convert to reference types to object.
The end-result is a no-op, so don't waste the allocation.
Running a spell checker on the whole solution revealed a couple more
typos. This fixes all of those (although internal // line comments are
mostly left alone).
Additionally, convert a very few string.Format occurrences to the pre-
dominant .FormatWith pattern and fix some incorrect message strings.
Primarily where it means one fewer field-access or simplifies
event delegate invocation, though one or two cases have just the
lesser advantage of allowing an IL stack dup rather than local access.
* Add references to types where they are missing.
* Fix incorrect references to closed generic types.
* Convert member ID strings to proper references where they can be
converted without breaking the build. The remaining member ID
strings usually mean that the comment would have to be rephrased
for at least one build target / platform.
* Drop namespaces from type names where they are unnecessary.
* Fix the odd typo and add additional <c> markup in a few places.
* Simple stuff: typos and missing punctuation and line breaks.
* Sometimes, two method overloads have quite different documentation.
Rephrase these to make them more similar.
* Minor rephrasings like in a previous commit (e.g. "...how output
should be formatted", "initializes a new instance of...").
* Obvious incorrect type references in comments. These appear mostly
in `Utilities/LinqBridge.cs` (nullable vs non-nullable).
* Remove factually incorrect statement about exceptions thrown.
* Remove comments for explicitly implemented interface methods.