Skip to content

Commit c198508

Browse files
authored
Merge pull request #337 from microsoft/feature/STJbase64
feat: replaces convert base64 by STJ base64 for performance
2 parents 666bf27 + 966015d commit c198508

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.11.3] - 2024-08-16
11+
12+
### Changed
13+
14+
- Replaced Convert.FromBase64 by System.Text.Json GetBytesFromBase64 to improve performance (10x improvement).
15+
1016
## [1.11.2] - 2024-08-14
1117

1218
### Changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<!-- Common default project properties for ALL projects-->
33
<PropertyGroup>
4-
<VersionPrefix>1.11.2</VersionPrefix>
4+
<VersionPrefix>1.11.3</VersionPrefix>
55
<VersionSuffix></VersionSuffix>
66
<!-- This is overidden in test projects by setting to true-->
77
<IsTestProject>false</IsTestProject>

src/serialization/json/JsonParseNode.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,9 @@ public IEnumerable<T> GetCollectionOfObjectValues<T>(ParsableFactory<T> factory)
268268
/// <returns>The byte array value of the node.</returns>
269269
public byte[]? GetByteArrayValue()
270270
{
271-
var rawValue = _jsonNode.GetString();
272-
if(string.IsNullOrEmpty(rawValue))
273-
return null;
274-
return Convert.FromBase64String(rawValue);
271+
if(_jsonNode.ValueKind is JsonValueKind.String && _jsonNode.TryGetBytesFromBase64(out var result))
272+
return result;
273+
return null;
275274
}
276275
/// <summary>
277276
/// Gets the untyped value of the node

src/serialization/json/JsonSerializationWriter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,14 @@ private void WriteDictionaryValue<T>(string? key, T values) where T : IDictionar
396396
/// <param name="value">The byte array to be written.</param>
397397
public void WriteByteArrayValue(string? key, byte[]? value)
398398
{
399-
if(value != null)//empty array is meaningful
400-
WriteStringValue(key, value.Length > 0 ? Convert.ToBase64String(value) : string.Empty);
399+
//empty array is meaningful
400+
if(value != null)
401+
{
402+
if(string.IsNullOrEmpty(key))
403+
writer.WriteBase64StringValue(value);
404+
else
405+
writer.WriteBase64String(key!, value);
406+
}
401407
}
402408

403409
/// <summary>

0 commit comments

Comments
 (0)