github axuno/SmartFormat v3.5.0

latest release: v3.5.1
3 months ago

What's Changed

Feature: Add interface IFormattingExtensionsToggle to skip formatting (#436)

  • Added the IFormattingExtensionsToggle interface to allow skipping formatting by IFormatter extensions.
  • This interface is primarily used by ISource extensions that receive it with the ISelectorInfo parameter.
  • By setting IFormattingExtensionsToggle.DisableFormattingExtensions to true, formatting can be skipped. This can be useful when the ISource found a value in ISource.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 for DefaultFormatter
  • 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 and IFormatter extensions into internal class Registry
  • 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 IFormatters:

  • 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 its Format
  • public bool TryGetValue(Placeholder, out object?): Tries to get the value for a Placeholder

Evaluator

  • Internal class that supplies the methods for evaluating Placeholder and Format objects
  • Contains the methods that FormattingInfo uses to evaluate Placeholder and Format objects
  • Has other methods formerly included in SmartFormatter that are now moved to Evaluator
  • Includes a partial class for handling events in all steps of the evaluation process

Registry

  • Internal class that contains all methods for handling ISource and IFormatter extensions that have been moved from SmartFormatter

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 to StringBuilderPool 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

Don't miss a new SmartFormat release

NewReleases is sending notifications on new releases.