Skip to content

Commit

Permalink
Merge pull request #240 from trivalik/memoryOptimization
Browse files Browse the repository at this point in the history
do not create empty arrays
  • Loading branch information
awcullen authored Jan 5, 2023
2 parents daa3563 + 094217d commit c9e05d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion UaClient/Collections/ErrorsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Workstation.Collections
/// <typeparam name="T">The type of the error object.</typeparam>
public class ErrorsContainer<T>
{
private static readonly T[] _noErrors = new T[0];
private static readonly T[] _noErrors = Array.Empty<T>();
private readonly Action<string> _raiseErrorsChanged;
private readonly Dictionary<string, List<T>> _validationResults;

Expand Down
9 changes: 4 additions & 5 deletions UaClient/ServiceModel/Ua/Channels/ClientSessionChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
using System.Threading.Tasks.Dataflow;
using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using System.Collections.Generic;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;

namespace Workstation.ServiceModel.Ua.Channels
Expand Down Expand Up @@ -619,7 +618,7 @@ protected override async Task OnOpenAsync(CancellationToken token = default)
throw new ServiceResultException(StatusCodes.BadIdentityTokenRejected);
}

byte[] passwordBytes = userNameIdentity.Password != null ? System.Text.Encoding.UTF8.GetBytes(userNameIdentity.Password) : new byte[0];
byte[] passwordBytes = userNameIdentity.Password != null ? System.Text.Encoding.UTF8.GetBytes(userNameIdentity.Password) : Array.Empty<byte>();
int plainTextLength = passwordBytes.Length + RemoteNonce!.Length;
IBufferedCipher encryptor;
byte[] cipherText;
Expand Down Expand Up @@ -809,7 +808,7 @@ private async Task PublishAsync(CancellationToken token = default)
var publishRequest = new PublishRequest
{
RequestHeader = new RequestHeader { TimeoutHint = _publishTimeoutHint, ReturnDiagnostics = _options.DiagnosticsHint },
SubscriptionAcknowledgements = new SubscriptionAcknowledgement[0]
SubscriptionAcknowledgements = Array.Empty<SubscriptionAcknowledgement>()
};
while (!token.IsCancellationRequested)
{
Expand All @@ -836,7 +835,7 @@ private async Task PublishAsync(CancellationToken token = default)
SubscriptionId = publishResponse.SubscriptionId
}
}
: new SubscriptionAcknowledgement[0]
: Array.Empty<SubscriptionAcknowledgement>()
};
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion UaClient/ServiceModel/Ua/EventHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static void RegisterSelectClauseAndDeserializer(Type type)
var clause = new SimpleAttributeOperand
{
TypeDefinitionId = NodeId.Parse(efa.TypeDefinitionId!),
BrowsePath = !String.IsNullOrWhiteSpace(efa.BrowsePath) ? efa.BrowsePath!.Split('/').Select(s => QualifiedName.Parse(s)).ToArray() : new QualifiedName[0],
BrowsePath = !String.IsNullOrWhiteSpace(efa.BrowsePath) ? efa.BrowsePath!.Split('/').Select(s => QualifiedName.Parse(s)).ToArray() : Array.Empty<QualifiedName>(),
AttributeId = efa.AttributeId,
IndexRange = efa.IndexRange
};
Expand Down

0 comments on commit c9e05d8

Please sign in to comment.