What's Changed
Feature: Add interface IFormattingExtensionsToggle to skip formatting (#436)
- Added the
IFormattingExtensionsToggle
interface to allow skipping formatting byIFormatter
extensions. - This interface is primarily used by
ISource
extensions that receive it with theISelectorInfo
parameter. - By setting
IFormattingExtensionsToggle.DisableFormattingExtensions
totrue
, formatting can be skipped. This can be useful when theISource
found a value inISource.TryEvaluateSelector
where default formatting cannot reasonably be done.
Security: Update of System.Text.Json (#435)
- Bumped
System.Text.Json
to v8.0.4 - Fixed a vulnerability in .NET when calling the JsonSerializer.DeserializeAsyncEnumerable method against an untrusted input using System.Text.Json, which could result in Denial of Service.
Feature: Implement ISpanFormattable for DefaultFormatter (#434)
- Implemented
ISpanFormattable
forDefaultFormatter
ISpanFormattable
is 5% faster than IFormattable, with 24% less allocations// Performance test case Smart.FormatInto(output, null, _placeholder0005Format, 1234567.890123f, 1234567.890123f, 1234567.890123f, 1234567.890123f, 1234567.890123f);
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3) 13th Gen Intel Core i7-13700K, 1 CPU, 24 logical and 16 physical cores .NET SDK 8.0.302 [Host] : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2 .NET 8.0 : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2 Job=.NET 8.0 Runtime=.NET 8.0 | Method | N | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | |------------------------- |------ |--------------:|------------:|------------:|------:|--------:|-----------:|-------------:|------------:| | ISpanFormattable | 100 | 74.502 us | 0.3693 us | 0.3273 us | 8.52 | 0.05 | 4.0283 | 62.5 KB | 2.76 | | IFormattable | 100 | 77.927 us | 0.5760 us | 0.5388 us | 8.91 | 0.07 | 5.2490 | 82.0 KB | 3.62 |
Feature: ReflectionSource (#426)
- Made
ReflectionSource.TypeCache
static
for better performance. - If the
static
cache has undesired effects on your code logic, consider to disable the cache (ReflectionSource.IsTypeCacheEnabled = false
). - Implemented a mechanism to control the size of
ReflectionSource.TypeCache
and remove the oldest item first.
Enhancement: DictionarySource (#426)
- Dynamics in
DictionarySource
now use case-sensitivity setting - Cache for
IReadOnlyDictionary
now has instance scope
Refactor: Split off classes Registry and Evaluator from SmartFormatter (#424)
SmartFormatter
- Separated members for handling
ISource
andIFormatter
extensions into internal classRegistry
- Separated members for evaluating formats into internal class
Evaluator
- Existing members of
SmartFormatter
remain unchanged and are not yet marked as obsolete
ZCharArray
- Added a lightweight, thread-safe container that rents a buffer from an
ArrayPool<char>
and returns it when disposed - Simplifies passing around the buffer without intermediate memory allocations
ZCharArray
contains most frequently used methods for writing data into the underlying buffer- Used in
FormattingInfo
methods (see below) for low memory allocation
FormattingInfo
Added methods useful in custom IFormatter
s:
- public ZCharArray FormattingInfo.FormatAsSpan(IFormatProvider, Format, object?): Works like SmartFormatter.Format(...) for the specified Format
- public ZCharArray FormattingInfo.FormatAsSpan(IFormatProvider, Placeholder, object?): Gets the value for the
Placeholder
and applies itsFormat
- public bool TryGetValue(Placeholder, out object?): Tries to get the value for a
Placeholder
Evaluator
- Internal class that supplies the methods for evaluating
Placeholder
andFormat
objects - Contains the methods that
FormattingInfo
uses to evaluatePlaceholder
andFormat
objects - Has other methods formerly included in
SmartFormatter
that are now moved toEvaluator
- Includes a partial class for handling events in all steps of the evaluation process
Registry
- Internal class that contains all methods for handling
ISource
andIFormatter
extensions that have been moved fromSmartFormatter
Feature: Format.HasNested checks for existing Placeholder in Items (#416)
- Added
Format.HasNested
property that checks Items for existing Placeholder
Test: Add unit test for nested scope (#404)
- Added unit test for nested scope
Enhancement: Ensure Format instances get returned to object pool (#402)
- Ensured that Format instances get returned to object pool
Refactor: Internal SmartFormat.Pooling
classes (#401)
- Simplified pooling classes and made methods and names more consistent
Chore: Remove unused performance test projects (#398)
- Removed unused performance test projects
Fix: Returning a StringBuilder exceeding default capacity to StringBuilderPool (#397)
- Fixed an issue where returning a
StringBuilder
exceeding the default capacity toStringBuilderPool
would throw an exception.
Refactor: Remove code duplications in SmartFormatter (#396)
- Removed code duplications in SmartFormatter
- Unified preprocessor directives
Chore: Remove redundant DependsOnTargets from SmartFormat.csproj (#394)
- Removed redundant DependsOnTargets from SmartFormat.csproj
Full Changelog: v3.4.0...v3.5.0