From 20024c46c53450294090f694537ec4c77c42a670 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 23 Jun 2026 12:59:14 +1000 Subject: [PATCH] Add Encoding.Preamble --- apiCount.include.md | 44 +++---- api_list.include.md | 2 + assemblySize.include.md | 80 ++++++------ readme.md | 128 ++++++++++--------- src/Consume/Consume.cs | 3 + src/Polyfill/EncodingPolyfill.cs | 12 ++ src/Split/net461/EncodingPolyfill.cs | 9 ++ src/Split/net462/EncodingPolyfill.cs | 9 ++ src/Split/net47/EncodingPolyfill.cs | 9 ++ src/Split/net471/EncodingPolyfill.cs | 9 ++ src/Split/net472/EncodingPolyfill.cs | 9 ++ src/Split/net48/EncodingPolyfill.cs | 9 ++ src/Split/net481/EncodingPolyfill.cs | 9 ++ src/Split/netcoreapp2.0/EncodingPolyfill.cs | 9 ++ src/Split/netstandard2.0/EncodingPolyfill.cs | 9 ++ src/Split/uap10.0/EncodingPolyfill.cs | 9 ++ src/Tests/PolyfillTests_Encoding.cs | 7 + 17 files changed, 242 insertions(+), 124 deletions(-) diff --git a/apiCount.include.md b/apiCount.include.md index f4671527..e4d4b645 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1,28 +1,28 @@ -**API count: 988** +**API count: 989** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 953 | -| `net462` | 953 | -| `net47` | 952 | -| `net471` | 951 | -| `net472` | 947 | -| `net48` | 947 | -| `net481` | 947 | -| `netstandard2.0` | 949 | -| `netstandard2.1` | 778 | -| `netcoreapp2.0` | 870 | -| `netcoreapp2.1` | 789 | -| `netcoreapp2.2` | 789 | -| `netcoreapp3.0` | 736 | -| `netcoreapp3.1` | 735 | -| `net5.0` | 607 | -| `net6.0` | 512 | -| `net7.0` | 359 | -| `net8.0` | 240 | -| `net9.0` | 164 | -| `net10.0` | 111 | +| `net461` | 962 | +| `net462` | 962 | +| `net47` | 961 | +| `net471` | 960 | +| `net472` | 956 | +| `net48` | 956 | +| `net481` | 956 | +| `netstandard2.0` | 958 | +| `netstandard2.1` | 787 | +| `netcoreapp2.0` | 879 | +| `netcoreapp2.1` | 797 | +| `netcoreapp2.2` | 797 | +| `netcoreapp3.0` | 744 | +| `netcoreapp3.1` | 743 | +| `net5.0` | 615 | +| `net6.0` | 520 | +| `net7.0` | 367 | +| `net8.0` | 248 | +| `net9.0` | 172 | +| `net10.0` | 119 | | `net11.0` | 58 | -| `uap10.0` | 937 | +| `uap10.0` | 948 | diff --git a/api_list.include.md b/api_list.include.md index 62afcd7c..b1131e31 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -307,6 +307,8 @@ * `bool TryGetBytes(ReadOnlySpan, Span, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.trygetbytes?view=net-11.0) * `bool TryGetChars(ReadOnlySpan, Span, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.trygetchars?view=net-11.0) * `Latin1` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.latin1?view=net-11.0) + * `Preamble` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.preamble?view=net-11.0) + * Note: Allocates a new array on each access, unlike the BCL property which returns a cached span. #### Enum diff --git a/assemblySize.include.md b/assemblySize.include.md index 644d918d..541947e4 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -2,26 +2,26 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 330.0KB | +322.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 283.5KB | +275.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 328.5KB | +320.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 332.0KB | +325.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 332.0KB | +325.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 331.0KB | +322.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 330.0KB | +321.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | -| net48 | 8.5KB | 330.0KB | +321.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | -| net481 | 8.5KB | 330.0KB | +321.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | -| netcoreapp2.0 | 9.0KB | 306.0KB | +297.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 286.0KB | +277.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp2.2 | 9.0KB | 286.0KB | +277.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp3.0 | 9.5KB | 278.5KB | +269.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 276.5KB | +267.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| net5.0 | 9.5KB | 240.0KB | +230.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net6.0 | 10.0KB | 181.5KB | +171.5KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | -| net7.0 | 10.0KB | 144.0KB | +134.0KB | +9.0KB | +5.0KB | +512bytes | +3.0KB | -| net8.0 | 9.5KB | 115.0KB | +105.5KB | +8.5KB | | +512bytes | +3.5KB | -| net9.0 | 9.5KB | 72.0KB | +62.5KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 48.5KB | +38.5KB | +9.0KB | | +1.0KB | +3.5KB | +| netstandard2.0 | 8.0KB | 337.5KB | +329.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | +| netstandard2.1 | 8.5KB | 291.0KB | +282.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 336.0KB | +327.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 339.5KB | +332.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 339.5KB | +332.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | +| net471 | 8.5KB | 338.5KB | +330.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 337.0KB | +328.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 337.0KB | +328.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 337.0KB | +328.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 313.5KB | +304.5KB | +8.5KB | +6.0KB | +8.5KB | +13.0KB | +| netcoreapp2.1 | 9.0KB | 293.0KB | +284.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 293.0KB | +284.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 285.5KB | +276.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 284.0KB | +274.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net5.0 | 9.5KB | 247.5KB | +238.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| net6.0 | 10.0KB | 188.5KB | +178.5KB | +10.0KB | +7.0KB | +1.0KB | +3.5KB | +| net7.0 | 10.0KB | 151.0KB | +141.0KB | +9.0KB | +5.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 122.5KB | +113.0KB | +8.5KB | | +512bytes | +3.5KB | +| net9.0 | 9.5KB | 79.5KB | +70.0KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 57.0KB | +47.0KB | +9.0KB | | +1.0KB | +3.5KB | | net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.0KB | | +512bytes | +3.5KB | @@ -29,24 +29,24 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 481.4KB | +473.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 409.6KB | +401.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 480.9KB | +472.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net462 | 7.0KB | 484.4KB | +477.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 484.2KB | +477.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 482.8KB | +474.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 480.8KB | +472.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | -| net48 | 8.5KB | 480.8KB | +472.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | -| net481 | 8.5KB | 480.8KB | +472.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | -| netcoreapp2.0 | 9.0KB | 447.0KB | +438.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 415.9KB | +406.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp2.2 | 9.0KB | 415.9KB | +406.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp3.0 | 9.5KB | 399.6KB | +390.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 397.6KB | +388.1KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| net5.0 | 9.5KB | 342.9KB | +333.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net6.0 | 10.0KB | 264.4KB | +254.4KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | -| net7.0 | 10.0KB | 208.3KB | +198.3KB | +16.6KB | +6.4KB | +1.1KB | +3.7KB | -| net8.0 | 9.5KB | 164.0KB | +154.5KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | -| net9.0 | 9.5KB | 100.7KB | +91.2KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 68.3KB | +58.3KB | +16.5KB | | +1.6KB | +4.2KB | +| netstandard2.0 | 8.0KB | 491.3KB | +483.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | +| netstandard2.1 | 8.5KB | 419.5KB | +411.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 490.8KB | +482.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net462 | 7.0KB | 494.3KB | +487.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 494.1KB | +487.1KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | +| net471 | 8.5KB | 492.7KB | +484.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net472 | 8.5KB | 490.2KB | +481.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 490.2KB | +481.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 490.2KB | +481.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 456.7KB | +447.7KB | +16.2KB | +7.7KB | +13.4KB | +18.4KB | +| netcoreapp2.1 | 9.0KB | 425.2KB | +416.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 425.2KB | +416.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 408.9KB | +399.4KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 407.4KB | +397.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net5.0 | 9.5KB | 352.7KB | +343.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| net6.0 | 10.0KB | 273.7KB | +263.7KB | +17.7KB | +8.7KB | +1.6KB | +4.2KB | +| net7.0 | 10.0KB | 217.6KB | +207.6KB | +16.6KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 174.1KB | +164.6KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 9.5KB | 110.7KB | +101.2KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 79.9KB | +69.9KB | +16.5KB | | +1.6KB | +4.2KB | | net11.0 | 10.0KB | 30.3KB | +20.3KB | +16.5KB | | +1.1KB | +4.2KB | diff --git a/readme.md b/readme.md index 93424ad5..48992e13 100644 --- a/readme.md +++ b/readme.md @@ -13,34 +13,34 @@ The package targets `netstandard2.0` and is designed to support the following ru * `uap10` -**API count: 986** +**API count: 989** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 951 | -| `net462` | 951 | -| `net47` | 950 | -| `net471` | 949 | -| `net472` | 945 | -| `net48` | 945 | -| `net481` | 945 | -| `netstandard2.0` | 947 | -| `netstandard2.1` | 778 | -| `netcoreapp2.0` | 870 | -| `netcoreapp2.1` | 789 | -| `netcoreapp2.2` | 789 | -| `netcoreapp3.0` | 736 | -| `netcoreapp3.1` | 735 | -| `net5.0` | 607 | -| `net6.0` | 512 | -| `net7.0` | 359 | -| `net8.0` | 240 | -| `net9.0` | 164 | -| `net10.0` | 111 | +| `net461` | 962 | +| `net462` | 962 | +| `net47` | 961 | +| `net471` | 960 | +| `net472` | 956 | +| `net48` | 956 | +| `net481` | 956 | +| `netstandard2.0` | 958 | +| `netstandard2.1` | 787 | +| `netcoreapp2.0` | 879 | +| `netcoreapp2.1` | 797 | +| `netcoreapp2.2` | 797 | +| `netcoreapp3.0` | 744 | +| `netcoreapp3.1` | 743 | +| `net5.0` | 615 | +| `net6.0` | 520 | +| `net7.0` | 367 | +| `net8.0` | 248 | +| `net9.0` | 172 | +| `net10.0` | 119 | | `net11.0` | 58 | -| `uap10.0` | 937 | +| `uap10.0` | 948 | @@ -96,26 +96,26 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 330.0KB | +322.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 283.5KB | +275.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 328.5KB | +320.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 332.0KB | +325.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 332.0KB | +325.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 331.0KB | +322.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 330.0KB | +321.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | -| net48 | 8.5KB | 330.0KB | +321.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | -| net481 | 8.5KB | 330.0KB | +321.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | -| netcoreapp2.0 | 9.0KB | 306.0KB | +297.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 286.0KB | +277.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp2.2 | 9.0KB | 286.0KB | +277.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp3.0 | 9.5KB | 278.5KB | +269.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 276.5KB | +267.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| net5.0 | 9.5KB | 240.0KB | +230.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net6.0 | 10.0KB | 181.5KB | +171.5KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | -| net7.0 | 10.0KB | 144.0KB | +134.0KB | +9.0KB | +5.0KB | +512bytes | +3.0KB | -| net8.0 | 9.5KB | 115.0KB | +105.5KB | +8.5KB | | +512bytes | +3.5KB | -| net9.0 | 9.5KB | 72.0KB | +62.5KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 48.5KB | +38.5KB | +9.0KB | | +1.0KB | +3.5KB | +| netstandard2.0 | 8.0KB | 337.5KB | +329.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | +| netstandard2.1 | 8.5KB | 291.0KB | +282.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 336.0KB | +327.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 339.5KB | +332.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 339.5KB | +332.5KB | +8.5KB | +6.0KB | +8.5KB | +13.5KB | +| net471 | 8.5KB | 338.5KB | +330.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 337.0KB | +328.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 337.0KB | +328.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 337.0KB | +328.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 313.5KB | +304.5KB | +8.5KB | +6.0KB | +8.5KB | +13.0KB | +| netcoreapp2.1 | 9.0KB | 293.0KB | +284.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 293.0KB | +284.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 285.5KB | +276.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 284.0KB | +274.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net5.0 | 9.5KB | 247.5KB | +238.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| net6.0 | 10.0KB | 188.5KB | +178.5KB | +10.0KB | +7.0KB | +1.0KB | +3.5KB | +| net7.0 | 10.0KB | 151.0KB | +141.0KB | +9.0KB | +5.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 122.5KB | +113.0KB | +8.5KB | | +512bytes | +3.5KB | +| net9.0 | 9.5KB | 79.5KB | +70.0KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 57.0KB | +47.0KB | +9.0KB | | +1.0KB | +3.5KB | | net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.0KB | | +512bytes | +3.5KB | @@ -123,26 +123,26 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 481.4KB | +473.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 409.6KB | +401.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 480.9KB | +472.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net462 | 7.0KB | 484.4KB | +477.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 484.2KB | +477.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 482.8KB | +474.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 480.8KB | +472.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | -| net48 | 8.5KB | 480.8KB | +472.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | -| net481 | 8.5KB | 480.8KB | +472.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | -| netcoreapp2.0 | 9.0KB | 447.0KB | +438.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 415.9KB | +406.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp2.2 | 9.0KB | 415.9KB | +406.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp3.0 | 9.5KB | 399.6KB | +390.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 397.6KB | +388.1KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| net5.0 | 9.5KB | 342.9KB | +333.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net6.0 | 10.0KB | 264.4KB | +254.4KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | -| net7.0 | 10.0KB | 208.3KB | +198.3KB | +16.6KB | +6.4KB | +1.1KB | +3.7KB | -| net8.0 | 9.5KB | 164.0KB | +154.5KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | -| net9.0 | 9.5KB | 100.7KB | +91.2KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 68.3KB | +58.3KB | +16.5KB | | +1.6KB | +4.2KB | +| netstandard2.0 | 8.0KB | 491.3KB | +483.3KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | +| netstandard2.1 | 8.5KB | 419.5KB | +411.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 490.8KB | +482.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net462 | 7.0KB | 494.3KB | +487.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 494.1KB | +487.1KB | +16.2KB | +7.7KB | +13.4KB | +18.9KB | +| net471 | 8.5KB | 492.7KB | +484.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net472 | 8.5KB | 490.2KB | +481.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 490.2KB | +481.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 490.2KB | +481.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 456.7KB | +447.7KB | +16.2KB | +7.7KB | +13.4KB | +18.4KB | +| netcoreapp2.1 | 9.0KB | 425.2KB | +416.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 425.2KB | +416.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 408.9KB | +399.4KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 407.4KB | +397.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net5.0 | 9.5KB | 352.7KB | +343.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| net6.0 | 10.0KB | 273.7KB | +263.7KB | +17.7KB | +8.7KB | +1.6KB | +4.2KB | +| net7.0 | 10.0KB | 217.6KB | +207.6KB | +16.6KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 174.1KB | +164.6KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 9.5KB | 110.7KB | +101.2KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 79.9KB | +69.9KB | +16.5KB | | +1.6KB | +4.2KB | | net11.0 | 10.0KB | 30.3KB | +20.3KB | +16.5KB | | +1.1KB | +4.2KB | @@ -838,6 +838,8 @@ The class `Polyfill` includes the following extension methods: * `bool TryGetBytes(ReadOnlySpan, Span, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.trygetbytes?view=net-11.0) * `bool TryGetChars(ReadOnlySpan, Span, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.trygetchars?view=net-11.0) * `Latin1` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.latin1?view=net-11.0) + * `Preamble` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.preamble?view=net-11.0) + * Note: Allocates a new array on each access, unlike the BCL property which returns a cached span. #### Enum @@ -1337,6 +1339,8 @@ The class `Polyfill` includes the following extension methods: * Note: No-op on older targets; the BCL grows the backing storage. * `void TrimExcess(int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1.trimexcess?view=net-11.0#system-collections-generic-queue-1-trimexcess(system-int32)) * Note: No-op on older targets; the BCL shrinks the backing storage. + * `bool TryDequeue(T)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1.trydequeue?view=net-11.0) + * `bool TryPeek(T)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1.trypeek?view=net-11.0) #### Random diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index ba6ab4a7..74daab23 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -796,6 +796,9 @@ void Enum_Methods() void Encoding_Methods() { var latin1 = Encoding.Latin1; +#if FeatureMemory + var preamble = Encoding.UTF8.Preamble; +#endif } void Environment_Methods() diff --git a/src/Polyfill/EncodingPolyfill.cs b/src/Polyfill/EncodingPolyfill.cs index 77b6f068..3eafa2fc 100644 --- a/src/Polyfill/EncodingPolyfill.cs +++ b/src/Polyfill/EncodingPolyfill.cs @@ -16,5 +16,17 @@ static partial class Polyfill //Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.latin1?view=net-11.0 public static Encoding Latin1 => latin1; } + +#if FeatureMemory && !NETCOREAPP2_1_OR_GREATER && !NETSTANDARD2_1_OR_GREATER + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.preamble?view=net-11.0 + //Note: Allocates a new array on each access, unlike the BCL property which returns a cached span. + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } #endif diff --git a/src/Split/net461/EncodingPolyfill.cs b/src/Split/net461/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net461/EncodingPolyfill.cs +++ b/src/Split/net461/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/net462/EncodingPolyfill.cs b/src/Split/net462/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net462/EncodingPolyfill.cs +++ b/src/Split/net462/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/net47/EncodingPolyfill.cs b/src/Split/net47/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net47/EncodingPolyfill.cs +++ b/src/Split/net47/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/net471/EncodingPolyfill.cs b/src/Split/net471/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net471/EncodingPolyfill.cs +++ b/src/Split/net471/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/net472/EncodingPolyfill.cs b/src/Split/net472/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net472/EncodingPolyfill.cs +++ b/src/Split/net472/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/net48/EncodingPolyfill.cs b/src/Split/net48/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net48/EncodingPolyfill.cs +++ b/src/Split/net48/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/net481/EncodingPolyfill.cs b/src/Split/net481/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/net481/EncodingPolyfill.cs +++ b/src/Split/net481/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/netcoreapp2.0/EncodingPolyfill.cs b/src/Split/netcoreapp2.0/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/netcoreapp2.0/EncodingPolyfill.cs +++ b/src/Split/netcoreapp2.0/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/netstandard2.0/EncodingPolyfill.cs b/src/Split/netstandard2.0/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/netstandard2.0/EncodingPolyfill.cs +++ b/src/Split/netstandard2.0/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Split/uap10.0/EncodingPolyfill.cs b/src/Split/uap10.0/EncodingPolyfill.cs index 3611d253..b2044b65 100644 --- a/src/Split/uap10.0/EncodingPolyfill.cs +++ b/src/Split/uap10.0/EncodingPolyfill.cs @@ -12,4 +12,13 @@ static partial class Polyfill /// public static Encoding Latin1 => latin1; } +#if FeatureMemory + extension(Encoding target) + { + /// + /// When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used. + /// + public System.ReadOnlySpan Preamble => target.GetPreamble(); + } +#endif } diff --git a/src/Tests/PolyfillTests_Encoding.cs b/src/Tests/PolyfillTests_Encoding.cs index 4f70bb68..ad325003 100644 --- a/src/Tests/PolyfillTests_Encoding.cs +++ b/src/Tests/PolyfillTests_Encoding.cs @@ -9,6 +9,13 @@ public async Task Encoding_Latin1() } #if FeatureMemory + [Test] + public async Task Encoding_Preamble() + { + var preamble = Encoding.UTF8.Preamble.ToArray(); + await Assert.That(preamble).IsEquivalentTo(new byte[] { 0xEF, 0xBB, 0xBF }); + } + [Test] public async Task Encoding_GetByteCount() {