Commit 743d3ca8 authored by Marc Gravell's avatar Marc Gravell

make use of "in" for larger readonly structs on non-public APIs

parent 7de44835
...@@ -28,7 +28,7 @@ namespace StackExchange.Redis ...@@ -28,7 +28,7 @@ namespace StackExchange.Redis
/// <param name="obj">The <see cref="object"/> to compare.</param> /// <param name="obj">The <see cref="object"/> to compare.</param>
public override bool Equals(object obj) => obj is ChannelMessage cm public override bool Equals(object obj) => obj is ChannelMessage cm
&& cm.Channel == Channel && cm.Message == Message; && cm.Channel == Channel && cm.Message == Message;
internal ChannelMessage(ChannelMessageQueue queue, RedisChannel channel, RedisValue value) internal ChannelMessage(ChannelMessageQueue queue, in RedisChannel channel, in RedisValue value)
{ {
_queue = queue; _queue = queue;
Channel = channel; Channel = channel;
...@@ -73,7 +73,7 @@ public sealed class ChannelMessageQueue ...@@ -73,7 +73,7 @@ public sealed class ChannelMessageQueue
/// </summary> /// </summary>
public Task Completion => _queue.Reader.Completion; public Task Completion => _queue.Reader.Completion;
internal ChannelMessageQueue(RedisChannel redisChannel, RedisSubscriber parent) internal ChannelMessageQueue(in RedisChannel redisChannel, RedisSubscriber parent)
{ {
Channel = redisChannel; Channel = redisChannel;
_parent = parent; _parent = parent;
...@@ -89,7 +89,9 @@ internal ChannelMessageQueue(RedisChannel redisChannel, RedisSubscriber parent) ...@@ -89,7 +89,9 @@ internal ChannelMessageQueue(RedisChannel redisChannel, RedisSubscriber parent)
internal void Subscribe(CommandFlags flags) => _parent.Subscribe(Channel, HandleMessage, flags); internal void Subscribe(CommandFlags flags) => _parent.Subscribe(Channel, HandleMessage, flags);
internal Task SubscribeAsync(CommandFlags flags) => _parent.SubscribeAsync(Channel, HandleMessage, flags); internal Task SubscribeAsync(CommandFlags flags) => _parent.SubscribeAsync(Channel, HandleMessage, flags);
#pragma warning disable RCS1231 // Make parameter ref read-only. - uses as a delegate for Action<RedisChannel, RedisValue>
private void HandleMessage(RedisChannel channel, RedisValue value) private void HandleMessage(RedisChannel channel, RedisValue value)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
var writer = _queue.Writer; var writer = _queue.Writer;
if (channel.IsNull && value.IsNull) // see ForSyncShutdown if (channel.IsNull && value.IsNull) // see ForSyncShutdown
......
...@@ -46,7 +46,9 @@ public override int GetHashCode() ...@@ -46,7 +46,9 @@ public override int GetHashCode()
} }
public override bool Equals(object obj) => obj is CommandBytes cb && Equals(cb); public override bool Equals(object obj) => obj is CommandBytes cb && Equals(cb);
public bool Equals(CommandBytes other) => _0 == other._0 && _1 == other._1 && _2 == other._2; bool IEquatable<CommandBytes>.Equals(CommandBytes other) => _0 == other._0 && _1 == other._1 && _2 == other._2;
public bool Equals(in CommandBytes other) => _0 == other._0 && _1 == other._1 && _2 == other._2;
// note: don't add == operators; with the implicit op above, that invalidates "==null" compiler checks (which should report a failure!) // note: don't add == operators; with the implicit op above, that invalidates "==null" compiler checks (which should report a failure!)
...@@ -74,7 +76,9 @@ public unsafe int Length ...@@ -74,7 +76,9 @@ public unsafe int Length
public bool IsEmpty => _0 == 0L; // cheap way of checking zero length public bool IsEmpty => _0 == 0L; // cheap way of checking zero length
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny!
public unsafe void CopyTo(Span<byte> target) public unsafe void CopyTo(Span<byte> target)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
fixed (ulong* uPtr = &_0) fixed (ulong* uPtr = &_0)
{ {
...@@ -114,7 +118,9 @@ public unsafe CommandBytes(string value) ...@@ -114,7 +118,9 @@ public unsafe CommandBytes(string value)
} }
} }
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny!
public unsafe CommandBytes(ReadOnlySpan<byte> value) public unsafe CommandBytes(ReadOnlySpan<byte> value)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
if (value.Length > MaxLength) throw new ArgumentOutOfRangeException("Maximum command length exceeed: " + value.Length + " bytes"); if (value.Length > MaxLength) throw new ArgumentOutOfRangeException("Maximum command length exceeed: " + value.Length + " bytes");
_0 = _1 = _2 = 0L; _0 = _1 = _2 = 0L;
...@@ -125,7 +131,8 @@ public unsafe CommandBytes(ReadOnlySpan<byte> value) ...@@ -125,7 +131,8 @@ public unsafe CommandBytes(ReadOnlySpan<byte> value)
*bPtr = (byte)UpperCasify(value.Length, bPtr + 1); *bPtr = (byte)UpperCasify(value.Length, bPtr + 1);
} }
} }
public unsafe CommandBytes(ReadOnlySequence<byte> value)
public unsafe CommandBytes(in ReadOnlySequence<byte> value)
{ {
if (value.Length > MaxLength) throw new ArgumentOutOfRangeException("Maximum command length exceeed"); if (value.Length > MaxLength) throw new ArgumentOutOfRangeException("Maximum command length exceeed");
int len = unchecked((int)value.Length); int len = unchecked((int)value.Length);
......
...@@ -1896,7 +1896,7 @@ internal ServerEndPoint SelectServer(Message message) ...@@ -1896,7 +1896,7 @@ internal ServerEndPoint SelectServer(Message message)
return ServerSelectionStrategy.Select(message); return ServerSelectionStrategy.Select(message);
} }
internal ServerEndPoint SelectServer(RedisCommand command, CommandFlags flags, RedisKey key) internal ServerEndPoint SelectServer(RedisCommand command, CommandFlags flags, in RedisKey key)
{ {
return ServerSelectionStrategy.Select(command, key, flags); return ServerSelectionStrategy.Select(command, key, flags);
} }
......
...@@ -125,7 +125,9 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include ...@@ -125,7 +125,9 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include
return ex; return ex;
} }
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny!
internal static Exception PopulateInnerExceptions(ReadOnlySpan<ServerEndPoint> serverSnapshot) internal static Exception PopulateInnerExceptions(ReadOnlySpan<ServerEndPoint> serverSnapshot)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
var innerExceptions = new List<Exception>(); var innerExceptions = new List<Exception>();
......
...@@ -68,7 +68,7 @@ public enum GeoRadiusOptions ...@@ -68,7 +68,7 @@ public enum GeoRadiusOptions
/// <param name="distance">Tthe distance from the result.</param> /// <param name="distance">Tthe distance from the result.</param>
/// <param name="hash">The hash of the result.</param> /// <param name="hash">The hash of the result.</param>
/// <param name="position">The geo position of the result.</param> /// <param name="position">The geo position of the result.</param>
internal GeoRadiusResult(RedisValue member, double? distance, long? hash, GeoPosition? position) internal GeoRadiusResult(in RedisValue member, double? distance, long? hash, GeoPosition? position)
{ {
Member = member; Member = member;
Distance = distance; Distance = distance;
...@@ -140,21 +140,27 @@ public GeoPosition(double longitude, double latitude) ...@@ -140,21 +140,27 @@ public GeoPosition(double longitude, double latitude)
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
/// <param name="other">The <see cref="GeoPosition"/> to compare to.</param> /// <param name="other">The <see cref="GeoPosition"/> to compare to.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public bool Equals(GeoPosition other) => this == other; public bool Equals(GeoPosition other) => this == other;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
/// <param name="x">The first position to compare.</param> /// <param name="x">The first position to compare.</param>
/// <param name="y">The second position to compare.</param> /// <param name="y">The second position to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(GeoPosition x, GeoPosition y) => x.Longitude == y.Longitude && x.Latitude == y.Latitude; public static bool operator ==(GeoPosition x, GeoPosition y) => x.Longitude == y.Longitude && x.Latitude == y.Latitude;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Compares two values for non-equality /// Compares two values for non-equality
/// </summary> /// </summary>
/// <param name="x">The first position to compare.</param> /// <param name="x">The first position to compare.</param>
/// <param name="y">The second position to compare.</param> /// <param name="y">The second position to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(GeoPosition x, GeoPosition y) => x.Longitude != y.Longitude || x.Latitude != y.Latitude; public static bool operator !=(GeoPosition x, GeoPosition y) => x.Longitude != y.Longitude || x.Latitude != y.Latitude;
#pragma warning restore RCS1231 // Make parameter ref read-only.
} }
/// <summary> /// <summary>
...@@ -179,7 +185,9 @@ public GeoPosition(double longitude, double latitude) ...@@ -179,7 +185,9 @@ public GeoPosition(double longitude, double latitude)
/// <param name="longitude">The longitude position to use.</param> /// <param name="longitude">The longitude position to use.</param>
/// <param name="latitude">The latitude position to use.</param> /// <param name="latitude">The latitude position to use.</param>
/// <param name="member">The value to store for this position.</param> /// <param name="member">The value to store for this position.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public GeoEntry(double longitude, double latitude, RedisValue member) public GeoEntry(double longitude, double latitude, RedisValue member)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
Member = member; Member = member;
Position = new GeoPosition(longitude, latitude); Position = new GeoPosition(longitude, latitude);
...@@ -222,13 +230,17 @@ public GeoEntry(double longitude, double latitude, RedisValue member) ...@@ -222,13 +230,17 @@ public GeoEntry(double longitude, double latitude, RedisValue member)
/// </summary> /// </summary>
/// <param name="x">The first entry to compare.</param> /// <param name="x">The first entry to compare.</param>
/// <param name="y">The second entry to compare.</param> /// <param name="y">The second entry to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(GeoEntry x, GeoEntry y) => x.Position == y.Position && x.Member == y.Member; public static bool operator ==(GeoEntry x, GeoEntry y) => x.Position == y.Position && x.Member == y.Member;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Compares two values for non-equality /// Compares two values for non-equality
/// </summary> /// </summary>
/// <param name="x">The first entry to compare.</param> /// <param name="x">The first entry to compare.</param>
/// <param name="y">The second entry to compare.</param> /// <param name="y">The second entry to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(GeoEntry x, GeoEntry y) => x.Position != y.Position || x.Member != y.Member; public static bool operator !=(GeoEntry x, GeoEntry y) => x.Position != y.Position || x.Member != y.Member;
#pragma warning restore RCS1231 // Make parameter ref read-only.
} }
} }
...@@ -217,62 +217,62 @@ public static Message Create(int db, CommandFlags flags, RedisCommand command) ...@@ -217,62 +217,62 @@ public static Message Create(int db, CommandFlags flags, RedisCommand command)
return new CommandMessage(db, flags, command); return new CommandMessage(db, flags, command);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key)
{ {
return new CommandKeyMessage(db, flags, command, key); return new CommandKeyMessage(db, flags, command, key);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisKey key1) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, in RedisKey key1)
{ {
return new CommandKeyKeyMessage(db, flags, command, key0, key1); return new CommandKeyKeyMessage(db, flags, command, key0, key1);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisKey key1, RedisValue value) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, in RedisKey key1, in RedisValue value)
{ {
return new CommandKeyKeyValueMessage(db, flags, command, key0, key1, value); return new CommandKeyKeyValueMessage(db, flags, command, key0, key1, value);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisKey key1, RedisKey key2) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, in RedisKey key1, in RedisKey key2)
{ {
return new CommandKeyKeyKeyMessage(db, flags, command, key0, key1, key2); return new CommandKeyKeyKeyMessage(db, flags, command, key0, key1, key2);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisValue value) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisValue value)
{ {
return new CommandValueMessage(db, flags, command, value); return new CommandValueMessage(db, flags, command, value);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value)
{ {
return new CommandKeyValueMessage(db, flags, command, key, value); return new CommandKeyValueMessage(db, flags, command, key, value);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisChannel channel) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisChannel channel)
{ {
return new CommandChannelMessage(db, flags, command, channel); return new CommandChannelMessage(db, flags, command, channel);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisChannel channel, RedisValue value) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisChannel channel, in RedisValue value)
{ {
return new CommandChannelValueMessage(db, flags, command, channel, value); return new CommandChannelValueMessage(db, flags, command, channel, value);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisValue value, RedisChannel channel) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisValue value, in RedisChannel channel)
{ {
return new CommandValueChannelMessage(db, flags, command, value, channel); return new CommandValueChannelMessage(db, flags, command, value, channel);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value0, RedisValue value1) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value0, in RedisValue value1)
{ {
return new CommandKeyValueValueMessage(db, flags, command, key, value0, value1); return new CommandKeyValueValueMessage(db, flags, command, key, value0, value1);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value0, RedisValue value1, RedisValue value2) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value0, in RedisValue value1, in RedisValue value2)
{ {
return new CommandKeyValueValueValueMessage(db, flags, command, key, value0, value1, value2); return new CommandKeyValueValueValueMessage(db, flags, command, key, value0, value1, value2);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, GeoEntry[] values) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, GeoEntry[] values)
{ {
if (values == null) throw new ArgumentNullException(nameof(values)); if (values == null) throw new ArgumentNullException(nameof(values));
if (values.Length == 0) if (values.Length == 0)
...@@ -295,27 +295,27 @@ public static Message Create(int db, CommandFlags flags, RedisCommand command, R ...@@ -295,27 +295,27 @@ public static Message Create(int db, CommandFlags flags, RedisCommand command, R
return new CommandKeyValuesMessage(db, flags, command, key, arr); return new CommandKeyValuesMessage(db, flags, command, key, arr);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value0, RedisValue value1, RedisValue value2, RedisValue value3) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value0, in RedisValue value1, in RedisValue value2, in RedisValue value3)
{ {
return new CommandKeyValueValueValueValueMessage(db, flags, command, key, value0, value1, value2, value3); return new CommandKeyValueValueValueValueMessage(db, flags, command, key, value0, value1, value2, value3);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisValue value0, RedisValue value1) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisValue value0, in RedisValue value1)
{ {
return new CommandValueValueMessage(db, flags, command, value0, value1); return new CommandValueValueMessage(db, flags, command, value0, value1);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisValue value, RedisKey key) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisValue value, in RedisKey key)
{ {
return new CommandValueKeyMessage(db, flags, command, value, key); return new CommandValueKeyMessage(db, flags, command, value, key);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisValue value0, RedisValue value1, RedisValue value2) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisValue value0, in RedisValue value1, in RedisValue value2)
{ {
return new CommandValueValueValueMessage(db, flags, command, value0, value1, value2); return new CommandValueValueValueMessage(db, flags, command, value0, value1, value2);
} }
public static Message Create(int db, CommandFlags flags, RedisCommand command, RedisValue value0, RedisValue value1, RedisValue value2, RedisValue value3, RedisValue value4) public static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisValue value0, in RedisValue value1, in RedisValue value2, in RedisValue value3, in RedisValue value4)
{ {
return new CommandValueValueValueValueValueMessage(db, flags, command, value0, value1, value2, value3, value4); return new CommandValueValueValueValueValueMessage(db, flags, command, value0, value1, value2, value3, value4);
} }
...@@ -467,7 +467,7 @@ public bool TryComplete(bool isAsync) ...@@ -467,7 +467,7 @@ public bool TryComplete(bool isAsync)
} }
} }
internal static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisKey[] keys) internal static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, RedisKey[] keys)
{ {
switch (keys.Length) switch (keys.Length)
{ {
...@@ -504,7 +504,7 @@ internal static Message Create(int db, CommandFlags flags, RedisCommand command, ...@@ -504,7 +504,7 @@ internal static Message Create(int db, CommandFlags flags, RedisCommand command,
} }
} }
internal static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue[] values) internal static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key, RedisValue[] values)
{ {
if (values == null) throw new ArgumentNullException(nameof(values)); if (values == null) throw new ArgumentNullException(nameof(values));
switch (values.Length) switch (values.Length)
...@@ -518,7 +518,7 @@ internal static Message Create(int db, CommandFlags flags, RedisCommand command, ...@@ -518,7 +518,7 @@ internal static Message Create(int db, CommandFlags flags, RedisCommand command,
} }
} }
internal static Message Create(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisValue[] values, RedisKey key1) internal static Message Create(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, RedisValue[] values, in RedisKey key1)
{ {
if (values == null) throw new ArgumentNullException(nameof(values)); if (values == null) throw new ArgumentNullException(nameof(values));
return new CommandKeyValuesKeyMessage(db, flags, command, key0, values, key1); return new CommandKeyValuesKeyMessage(db, flags, command, key0, values, key1);
...@@ -583,7 +583,7 @@ internal static CommandFlags SetMasterSlaveFlags(CommandFlags everything, Comman ...@@ -583,7 +583,7 @@ internal static CommandFlags SetMasterSlaveFlags(CommandFlags everything, Comman
internal void Cancel() => resultBox?.Cancel(); internal void Cancel() => resultBox?.Cancel();
// true if ready to be completed (i.e. false if re-issued to another server) // true if ready to be completed (i.e. false if re-issued to another server)
internal bool ComputeResult(PhysicalConnection connection, RawResult result) internal bool ComputeResult(PhysicalConnection connection, in RawResult result)
{ {
var box = resultBox; var box = resultBox;
try try
...@@ -746,7 +746,7 @@ internal abstract class CommandChannelBase : Message ...@@ -746,7 +746,7 @@ internal abstract class CommandChannelBase : Message
{ {
protected readonly RedisChannel Channel; protected readonly RedisChannel Channel;
protected CommandChannelBase(int db, CommandFlags flags, RedisCommand command, RedisChannel channel) : base(db, flags, command) protected CommandChannelBase(int db, CommandFlags flags, RedisCommand command, in RedisChannel channel) : base(db, flags, command)
{ {
channel.AssertNotNull(); channel.AssertNotNull();
Channel = channel; Channel = channel;
...@@ -759,7 +759,7 @@ internal abstract class CommandKeyBase : Message ...@@ -759,7 +759,7 @@ internal abstract class CommandKeyBase : Message
{ {
protected readonly RedisKey Key; protected readonly RedisKey Key;
protected CommandKeyBase(int db, CommandFlags flags, RedisCommand command, RedisKey key) : base(db, flags, command) protected CommandKeyBase(int db, CommandFlags flags, RedisCommand command, in RedisKey key) : base(db, flags, command)
{ {
key.AssertNotNull(); key.AssertNotNull();
Key = key; Key = key;
...@@ -775,7 +775,7 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) ...@@ -775,7 +775,7 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
private sealed class CommandChannelMessage : CommandChannelBase private sealed class CommandChannelMessage : CommandChannelBase
{ {
public CommandChannelMessage(int db, CommandFlags flags, RedisCommand command, RedisChannel channel) : base(db, flags, command, channel) public CommandChannelMessage(int db, CommandFlags flags, RedisCommand command, in RedisChannel channel) : base(db, flags, command, channel)
{ } { }
protected override void WriteImpl(PhysicalConnection physical) protected override void WriteImpl(PhysicalConnection physical)
{ {
...@@ -788,7 +788,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -788,7 +788,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandChannelValueMessage : CommandChannelBase private sealed class CommandChannelValueMessage : CommandChannelBase
{ {
private readonly RedisValue value; private readonly RedisValue value;
public CommandChannelValueMessage(int db, CommandFlags flags, RedisCommand command, RedisChannel channel, RedisValue value) : base(db, flags, command, channel) public CommandChannelValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisChannel channel, in RedisValue value) : base(db, flags, command, channel)
{ {
value.AssertNotNull(); value.AssertNotNull();
this.value = value; this.value = value;
...@@ -806,7 +806,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -806,7 +806,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyKeyKeyMessage : CommandKeyBase private sealed class CommandKeyKeyKeyMessage : CommandKeyBase
{ {
private readonly RedisKey key1, key2; private readonly RedisKey key1, key2;
public CommandKeyKeyKeyMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisKey key1, RedisKey key2) : base(db, flags, command, key0) public CommandKeyKeyKeyMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, in RedisKey key1, in RedisKey key2) : base(db, flags, command, key0)
{ {
key1.AssertNotNull(); key1.AssertNotNull();
key2.AssertNotNull(); key2.AssertNotNull();
...@@ -834,7 +834,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -834,7 +834,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private class CommandKeyKeyMessage : CommandKeyBase private class CommandKeyKeyMessage : CommandKeyBase
{ {
protected readonly RedisKey key1; protected readonly RedisKey key1;
public CommandKeyKeyMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisKey key1) : base(db, flags, command, key0) public CommandKeyKeyMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, in RedisKey key1) : base(db, flags, command, key0)
{ {
key1.AssertNotNull(); key1.AssertNotNull();
this.key1 = key1; this.key1 = key1;
...@@ -858,7 +858,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -858,7 +858,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyKeysMessage : CommandKeyBase private sealed class CommandKeyKeysMessage : CommandKeyBase
{ {
private readonly RedisKey[] keys; private readonly RedisKey[] keys;
public CommandKeyKeysMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisKey[] keys) : base(db, flags, command, key) public CommandKeyKeysMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key, RedisKey[] keys) : base(db, flags, command, key)
{ {
for (int i = 0; i < keys.Length; i++) for (int i = 0; i < keys.Length; i++)
{ {
...@@ -892,7 +892,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -892,7 +892,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyKeyValueMessage : CommandKeyKeyMessage private sealed class CommandKeyKeyValueMessage : CommandKeyKeyMessage
{ {
private readonly RedisValue value; private readonly RedisValue value;
public CommandKeyKeyValueMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisKey key1, RedisValue value) : base(db, flags, command, key0, key1) public CommandKeyKeyValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, in RedisKey key1, in RedisValue value) : base(db, flags, command, key0, key1)
{ {
value.AssertNotNull(); value.AssertNotNull();
this.value = value; this.value = value;
...@@ -911,7 +911,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -911,7 +911,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyMessage : CommandKeyBase private sealed class CommandKeyMessage : CommandKeyBase
{ {
public CommandKeyMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key) : base(db, flags, command, key) public CommandKeyMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key) : base(db, flags, command, key)
{ } { }
protected override void WriteImpl(PhysicalConnection physical) protected override void WriteImpl(PhysicalConnection physical)
{ {
...@@ -980,7 +980,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -980,7 +980,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyValueMessage : CommandKeyBase private sealed class CommandKeyValueMessage : CommandKeyBase
{ {
private readonly RedisValue value; private readonly RedisValue value;
public CommandKeyValueMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value) : base(db, flags, command, key) public CommandKeyValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value) : base(db, flags, command, key)
{ {
value.AssertNotNull(); value.AssertNotNull();
this.value = value; this.value = value;
...@@ -999,7 +999,7 @@ private sealed class CommandKeyValuesKeyMessage : CommandKeyBase ...@@ -999,7 +999,7 @@ private sealed class CommandKeyValuesKeyMessage : CommandKeyBase
{ {
private readonly RedisKey key1; private readonly RedisKey key1;
private readonly RedisValue[] values; private readonly RedisValue[] values;
public CommandKeyValuesKeyMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key0, RedisValue[] values, RedisKey key1) : base(db, flags, command, key0) public CommandKeyValuesKeyMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key0, RedisValue[] values, in RedisKey key1) : base(db, flags, command, key0)
{ {
for (int i = 0; i < values.Length; i++) for (int i = 0; i < values.Length; i++)
{ {
...@@ -1029,7 +1029,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1029,7 +1029,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyValuesMessage : CommandKeyBase private sealed class CommandKeyValuesMessage : CommandKeyBase
{ {
private readonly RedisValue[] values; private readonly RedisValue[] values;
public CommandKeyValuesMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue[] values) : base(db, flags, command, key) public CommandKeyValuesMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key, RedisValue[] values) : base(db, flags, command, key)
{ {
for (int i = 0; i < values.Length; i++) for (int i = 0; i < values.Length; i++)
{ {
...@@ -1050,7 +1050,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1050,7 +1050,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyValueValueMessage : CommandKeyBase private sealed class CommandKeyValueValueMessage : CommandKeyBase
{ {
private readonly RedisValue value0, value1; private readonly RedisValue value0, value1;
public CommandKeyValueValueMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value0, RedisValue value1) : base(db, flags, command, key) public CommandKeyValueValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value0, in RedisValue value1) : base(db, flags, command, key)
{ {
value0.AssertNotNull(); value0.AssertNotNull();
value1.AssertNotNull(); value1.AssertNotNull();
...@@ -1071,7 +1071,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1071,7 +1071,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyValueValueValueMessage : CommandKeyBase private sealed class CommandKeyValueValueValueMessage : CommandKeyBase
{ {
private readonly RedisValue value0, value1, value2; private readonly RedisValue value0, value1, value2;
public CommandKeyValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value0, RedisValue value1, RedisValue value2) : base(db, flags, command, key) public CommandKeyValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value0, in RedisValue value1, in RedisValue value2) : base(db, flags, command, key)
{ {
value0.AssertNotNull(); value0.AssertNotNull();
value1.AssertNotNull(); value1.AssertNotNull();
...@@ -1095,7 +1095,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1095,7 +1095,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandKeyValueValueValueValueMessage : CommandKeyBase private sealed class CommandKeyValueValueValueValueMessage : CommandKeyBase
{ {
private readonly RedisValue value0, value1, value2, value3; private readonly RedisValue value0, value1, value2, value3;
public CommandKeyValueValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value0, RedisValue value1, RedisValue value2, RedisValue value3) : base(db, flags, command, key) public CommandKeyValueValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisKey key, in RedisValue value0, in RedisValue value1, in RedisValue value2, in RedisValue value3) : base(db, flags, command, key)
{ {
value0.AssertNotNull(); value0.AssertNotNull();
value1.AssertNotNull(); value1.AssertNotNull();
...@@ -1164,7 +1164,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1164,7 +1164,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandValueChannelMessage : CommandChannelBase private sealed class CommandValueChannelMessage : CommandChannelBase
{ {
private readonly RedisValue value; private readonly RedisValue value;
public CommandValueChannelMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value, RedisChannel channel) : base(db, flags, command, channel) public CommandValueChannelMessage(int db, CommandFlags flags, RedisCommand command, in RedisValue value, in RedisChannel channel) : base(db, flags, command, channel)
{ {
value.AssertNotNull(); value.AssertNotNull();
this.value = value; this.value = value;
...@@ -1183,7 +1183,7 @@ private sealed class CommandValueKeyMessage : CommandKeyBase ...@@ -1183,7 +1183,7 @@ private sealed class CommandValueKeyMessage : CommandKeyBase
{ {
private readonly RedisValue value; private readonly RedisValue value;
public CommandValueKeyMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value, RedisKey key) : base(db, flags, command, key) public CommandValueKeyMessage(int db, CommandFlags flags, RedisCommand command, in RedisValue value, in RedisKey key) : base(db, flags, command, key)
{ {
value.AssertNotNull(); value.AssertNotNull();
this.value = value; this.value = value;
...@@ -1207,7 +1207,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1207,7 +1207,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandValueMessage : Message private sealed class CommandValueMessage : Message
{ {
private readonly RedisValue value; private readonly RedisValue value;
public CommandValueMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value) : base(db, flags, command) public CommandValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisValue value) : base(db, flags, command)
{ {
value.AssertNotNull(); value.AssertNotNull();
this.value = value; this.value = value;
...@@ -1224,7 +1224,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1224,7 +1224,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandValueValueMessage : Message private sealed class CommandValueValueMessage : Message
{ {
private readonly RedisValue value0, value1; private readonly RedisValue value0, value1;
public CommandValueValueMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value0, RedisValue value1) : base(db, flags, command) public CommandValueValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisValue value0, in RedisValue value1) : base(db, flags, command)
{ {
value0.AssertNotNull(); value0.AssertNotNull();
value1.AssertNotNull(); value1.AssertNotNull();
...@@ -1244,7 +1244,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1244,7 +1244,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandValueValueValueMessage : Message private sealed class CommandValueValueValueMessage : Message
{ {
private readonly RedisValue value0, value1, value2; private readonly RedisValue value0, value1, value2;
public CommandValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value0, RedisValue value1, RedisValue value2) : base(db, flags, command) public CommandValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisValue value0, in RedisValue value1, in RedisValue value2) : base(db, flags, command)
{ {
value0.AssertNotNull(); value0.AssertNotNull();
value1.AssertNotNull(); value1.AssertNotNull();
...@@ -1267,7 +1267,7 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -1267,7 +1267,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private sealed class CommandValueValueValueValueValueMessage : Message private sealed class CommandValueValueValueValueValueMessage : Message
{ {
private readonly RedisValue value0, value1, value2, value3, value4; private readonly RedisValue value0, value1, value2, value3, value4;
public CommandValueValueValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value0, RedisValue value1, RedisValue value2, RedisValue value3, RedisValue value4) : base(db, flags, command) public CommandValueValueValueValueValueMessage(int db, CommandFlags flags, RedisCommand command, in RedisValue value0, in RedisValue value1, in RedisValue value2, in RedisValue value3, in RedisValue value4) : base(db, flags, command)
{ {
value0.AssertNotNull(); value0.AssertNotNull();
value1.AssertNotNull(); value1.AssertNotNull();
......
...@@ -631,7 +631,7 @@ internal void SetUnknownDatabase() ...@@ -631,7 +631,7 @@ internal void SetUnknownDatabase()
currentDatabase = -1; currentDatabase = -1;
} }
internal void Write(RedisKey key) internal void Write(in RedisKey key)
{ {
var val = key.KeyValue; var val = key.KeyValue;
if (val is string s) if (val is string s)
...@@ -644,13 +644,13 @@ internal void Write(RedisKey key) ...@@ -644,13 +644,13 @@ internal void Write(RedisKey key)
} }
} }
internal void Write(RedisChannel channel) internal void Write(in RedisChannel channel)
=> WriteUnifiedPrefixedBlob(_ioPipe.Output, ChannelPrefix, channel.Value); => WriteUnifiedPrefixedBlob(_ioPipe.Output, ChannelPrefix, channel.Value);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void WriteBulkString(RedisValue value) internal void WriteBulkString(in RedisValue value)
=> WriteBulkString(value, _ioPipe.Output); => WriteBulkString(value, _ioPipe.Output);
internal static void WriteBulkString(RedisValue value, PipeWriter output) internal static void WriteBulkString(in RedisValue value, PipeWriter output)
{ {
switch (value.Type) switch (value.Type)
{ {
...@@ -889,7 +889,7 @@ private static void WriteUnifiedSpan(PipeWriter writer, ReadOnlySpan<byte> value ...@@ -889,7 +889,7 @@ private static void WriteUnifiedSpan(PipeWriter writer, ReadOnlySpan<byte> value
{ {
var span = writer.GetSpan(5 + MaxInt32TextLen + value.Length); var span = writer.GetSpan(5 + MaxInt32TextLen + value.Length);
span[0] = (byte)'$'; span[0] = (byte)'$';
int bytes = AppendToSpanSpan(span, value, 1); int bytes = AppendToSpan(span, value, 1);
writer.Advance(bytes); writer.Advance(bytes);
} }
else else
...@@ -906,7 +906,7 @@ private static void WriteUnifiedSpan(PipeWriter writer, ReadOnlySpan<byte> value ...@@ -906,7 +906,7 @@ private static void WriteUnifiedSpan(PipeWriter writer, ReadOnlySpan<byte> value
} }
} }
private static int AppendToSpanCommand(Span<byte> span, CommandBytes value, int offset = 0) private static int AppendToSpanCommand(Span<byte> span, in CommandBytes value, int offset = 0)
{ {
span[offset++] = (byte)'$'; span[offset++] = (byte)'$';
int len = value.Length; int len = value.Length;
...@@ -916,7 +916,9 @@ private static int AppendToSpanCommand(Span<byte> span, CommandBytes value, int ...@@ -916,7 +916,9 @@ private static int AppendToSpanCommand(Span<byte> span, CommandBytes value, int
return WriteCrlf(span, offset); return WriteCrlf(span, offset);
} }
private static int AppendToSpanSpan(Span<byte> span, ReadOnlySpan<byte> value, int offset = 0) #pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny
private static int AppendToSpan(Span<byte> span, ReadOnlySpan<byte> value, int offset = 0)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
offset = WriteRaw(span, value.Length, offset: offset); offset = WriteRaw(span, value.Length, offset: offset);
value.CopyTo(span.Slice(offset, value.Length)); value.CopyTo(span.Slice(offset, value.Length));
...@@ -1230,7 +1232,7 @@ internal async ValueTask<bool> ConnectedAsync(Socket socket, TextWriter log, Soc ...@@ -1230,7 +1232,7 @@ internal async ValueTask<bool> ConnectedAsync(Socket socket, TextWriter log, Soc
} }
} }
private void MatchResult(RawResult result) private void MatchResult(in RawResult result)
{ {
// check to see if it could be an out-of-band pubsub message // check to see if it could be an out-of-band pubsub message
if (connectionType == ConnectionType.Subscription && result.Type == ResultType.MultiBulk) if (connectionType == ConnectionType.Subscription && result.Type == ResultType.MultiBulk)
......
...@@ -27,7 +27,7 @@ namespace StackExchange.Redis ...@@ -27,7 +27,7 @@ namespace StackExchange.Redis
private const ResultType NonNullFlag = (ResultType)128; private const ResultType NonNullFlag = (ResultType)128;
public RawResult(ResultType resultType, ReadOnlySequence<byte> payload, bool isNull) public RawResult(ResultType resultType, in ReadOnlySequence<byte> payload, bool isNull)
{ {
switch (resultType) switch (resultType)
{ {
...@@ -91,7 +91,7 @@ public override string ToString() ...@@ -91,7 +91,7 @@ public override string ToString()
public Tokenizer GetEnumerator() => this; public Tokenizer GetEnumerator() => this;
private BufferReader _value; private BufferReader _value;
public Tokenizer(ReadOnlySequence<byte> value) public Tokenizer(in ReadOnlySequence<byte> value)
{ {
_value = new BufferReader(value); _value = new BufferReader(value);
Current = default; Current = default;
...@@ -209,7 +209,7 @@ internal void Recycle(int limit = -1) ...@@ -209,7 +209,7 @@ internal void Recycle(int limit = -1)
} }
} }
internal bool IsEqual(CommandBytes expected) internal bool IsEqual(in CommandBytes expected)
{ {
if (expected.Length != Payload.Length) return false; if (expected.Length != Payload.Length) return false;
return new CommandBytes(Payload).Equals(expected); return new CommandBytes(Payload).Equals(expected);
...@@ -236,7 +236,7 @@ internal unsafe bool IsEqual(byte[] expected) ...@@ -236,7 +236,7 @@ internal unsafe bool IsEqual(byte[] expected)
return true; return true;
} }
internal bool StartsWith(CommandBytes expected) internal bool StartsWith(in CommandBytes expected)
{ {
var len = expected.Length; var len = expected.Length;
if (len > Payload.Length) return false; if (len > Payload.Length) return false;
......
...@@ -56,73 +56,93 @@ private static bool DeterminePatternBased(byte[] value, PatternMode mode) ...@@ -56,73 +56,93 @@ private static bool DeterminePatternBased(byte[] value, PatternMode mode)
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(RedisChannel x, RedisChannel y) => !(x == y); public static bool operator !=(RedisChannel x, RedisChannel y) => !(x == y);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are not equal /// Indicate whether two channel names are not equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(string x, RedisChannel y) => !(x == y); public static bool operator !=(string x, RedisChannel y) => !(x == y);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are not equal /// Indicate whether two channel names are not equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(byte[] x, RedisChannel y) => !(x == y); public static bool operator !=(byte[] x, RedisChannel y) => !(x == y);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are not equal /// Indicate whether two channel names are not equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(RedisChannel x, string y) => !(x == y); public static bool operator !=(RedisChannel x, string y) => !(x == y);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are not equal /// Indicate whether two channel names are not equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator !=(RedisChannel x, byte[] y) => !(x == y); public static bool operator !=(RedisChannel x, byte[] y) => !(x == y);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are equal /// Indicate whether two channel names are equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(RedisChannel x, RedisChannel y) => public static bool operator ==(RedisChannel x, RedisChannel y) =>
x.IsPatternBased == y.IsPatternBased && RedisValue.Equals(x.Value, y.Value); x.IsPatternBased == y.IsPatternBased && RedisValue.Equals(x.Value, y.Value);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are equal /// Indicate whether two channel names are equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(string x, RedisChannel y) => public static bool operator ==(string x, RedisChannel y) =>
RedisValue.Equals(x == null ? null : Encoding.UTF8.GetBytes(x), y.Value); RedisValue.Equals(x == null ? null : Encoding.UTF8.GetBytes(x), y.Value);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are equal /// Indicate whether two channel names are equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(byte[] x, RedisChannel y) => RedisValue.Equals(x, y.Value); public static bool operator ==(byte[] x, RedisChannel y) => RedisValue.Equals(x, y.Value);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are equal /// Indicate whether two channel names are equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(RedisChannel x, string y) => public static bool operator ==(RedisChannel x, string y) =>
RedisValue.Equals(x.Value, y == null ? null : Encoding.UTF8.GetBytes(y)); RedisValue.Equals(x.Value, y == null ? null : Encoding.UTF8.GetBytes(y));
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Indicate whether two channel names are equal /// Indicate whether two channel names are equal
/// </summary> /// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param> /// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param> /// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static bool operator ==(RedisChannel x, byte[] y) => RedisValue.Equals(x.Value, y); public static bool operator ==(RedisChannel x, byte[] y) => RedisValue.Equals(x.Value, y);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// See Object.Equals /// See Object.Equals
...@@ -223,13 +243,17 @@ public enum PatternMode ...@@ -223,13 +243,17 @@ public enum PatternMode
/// Obtain the channel name as a <see cref="T:byte[]"/>. /// Obtain the channel name as a <see cref="T:byte[]"/>.
/// </summary> /// </summary>
/// <param name="key">The channel to get a byte[] from.</param> /// <param name="key">The channel to get a byte[] from.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static implicit operator byte[] (RedisChannel key) => key.Value; public static implicit operator byte[] (RedisChannel key) => key.Value;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary> /// <summary>
/// Obtain the channel name as a <see cref="string"/>. /// Obtain the channel name as a <see cref="string"/>.
/// </summary> /// </summary>
/// <param name="key">The channel to get a string from.</param> /// <param name="key">The channel to get a string from.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public static implicit operator string (RedisChannel key) public static implicit operator string (RedisChannel key)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{ {
var arr = key.Value; var arr = key.Value;
if (arr == null) return null; if (arr == null) return null;
......
...@@ -176,7 +176,7 @@ private static readonly RedisValue ...@@ -176,7 +176,7 @@ private static readonly RedisValue
COUNT = Encoding.ASCII.GetBytes("COUNT"), COUNT = Encoding.ASCII.GetBytes("COUNT"),
ASC = Encoding.ASCII.GetBytes("ASC"), ASC = Encoding.ASCII.GetBytes("ASC"),
DESC = Encoding.ASCII.GetBytes("DESC"); DESC = Encoding.ASCII.GetBytes("DESC");
private Message GetGeoRadiusMessage(RedisKey key, RedisValue? member, double longitude, double latitude, double radius, GeoUnit unit, int count, Order? order, GeoRadiusOptions options, CommandFlags flags) private Message GetGeoRadiusMessage(in RedisKey key, RedisValue? member, double longitude, double latitude, double radius, GeoUnit unit, int count, Order? order, GeoRadiusOptions options, CommandFlags flags)
{ {
var redisValues = new List<RedisValue>(); var redisValues = new List<RedisValue>();
RedisCommand command; RedisCommand command;
...@@ -2419,7 +2419,7 @@ public Task<RedisValue> StringSetRangeAsync(RedisKey key, long offset, RedisValu ...@@ -2419,7 +2419,7 @@ public Task<RedisValue> StringSetRangeAsync(RedisKey key, long offset, RedisValu
return ExecuteAsync(msg, ResultProcessor.RedisValue); return ExecuteAsync(msg, ResultProcessor.RedisValue);
} }
private Message GetExpiryMessage(RedisKey key, CommandFlags flags, TimeSpan? expiry, out ServerEndPoint server) private Message GetExpiryMessage(in RedisKey key, CommandFlags flags, TimeSpan? expiry, out ServerEndPoint server)
{ {
TimeSpan duration; TimeSpan duration;
if (expiry == null || (duration = expiry.Value) == TimeSpan.MaxValue) if (expiry == null || (duration = expiry.Value) == TimeSpan.MaxValue)
...@@ -2441,7 +2441,7 @@ private Message GetExpiryMessage(RedisKey key, CommandFlags flags, TimeSpan? exp ...@@ -2441,7 +2441,7 @@ private Message GetExpiryMessage(RedisKey key, CommandFlags flags, TimeSpan? exp
return Message.Create(Database, flags, RedisCommand.EXPIRE, key, seconds); return Message.Create(Database, flags, RedisCommand.EXPIRE, key, seconds);
} }
private Message GetExpiryMessage(RedisKey key, CommandFlags flags, DateTime? expiry, out ServerEndPoint server) private Message GetExpiryMessage(in RedisKey key, CommandFlags flags, DateTime? expiry, out ServerEndPoint server)
{ {
DateTime when; DateTime when;
if (expiry == null || (when = expiry.Value) == DateTime.MaxValue) if (expiry == null || (when = expiry.Value) == DateTime.MaxValue)
...@@ -3686,7 +3686,7 @@ private class StringGetWithExpiryMessage : Message.CommandKeyBase, IMultiMessage ...@@ -3686,7 +3686,7 @@ private class StringGetWithExpiryMessage : Message.CommandKeyBase, IMultiMessage
private readonly RedisCommand ttlCommand; private readonly RedisCommand ttlCommand;
private ResultBox<TimeSpan?> box; private ResultBox<TimeSpan?> box;
public StringGetWithExpiryMessage(int db, CommandFlags flags, RedisCommand ttlCommand, RedisKey key) public StringGetWithExpiryMessage(int db, CommandFlags flags, RedisCommand ttlCommand, in RedisKey key)
: base(db, flags, RedisCommand.GET, key) : base(db, flags, RedisCommand.GET, key)
{ {
this.ttlCommand = ttlCommand; this.ttlCommand = ttlCommand;
......
...@@ -29,7 +29,7 @@ public partial class ConnectionMultiplexer ...@@ -29,7 +29,7 @@ public partial class ConnectionMultiplexer
return false; return false;
} }
internal Task AddSubscription(RedisChannel channel, Action<RedisChannel, RedisValue> handler, CommandFlags flags, object asyncState) internal Task AddSubscription(in RedisChannel channel, Action<RedisChannel, RedisValue> handler, CommandFlags flags, object asyncState)
{ {
if (handler != null) if (handler != null)
{ {
...@@ -52,7 +52,7 @@ internal Task AddSubscription(RedisChannel channel, Action<RedisChannel, RedisVa ...@@ -52,7 +52,7 @@ internal Task AddSubscription(RedisChannel channel, Action<RedisChannel, RedisVa
return CompletedTask<bool>.Default(asyncState); return CompletedTask<bool>.Default(asyncState);
} }
internal ServerEndPoint GetSubscribedServer(RedisChannel channel) internal ServerEndPoint GetSubscribedServer(in RedisChannel channel)
{ {
if (!channel.IsNullOrEmpty) if (!channel.IsNullOrEmpty)
{ {
...@@ -67,7 +67,7 @@ internal ServerEndPoint GetSubscribedServer(RedisChannel channel) ...@@ -67,7 +67,7 @@ internal ServerEndPoint GetSubscribedServer(RedisChannel channel)
return null; return null;
} }
internal void OnMessage(RedisChannel subscription, RedisChannel channel, RedisValue payload) internal void OnMessage(in RedisChannel subscription, in RedisChannel channel, in RedisValue payload)
{ {
ICompletable completable = null; ICompletable completable = null;
lock (subscriptions) lock (subscriptions)
...@@ -100,7 +100,7 @@ internal Task RemoveAllSubscriptions(CommandFlags flags, object asyncState) ...@@ -100,7 +100,7 @@ internal Task RemoveAllSubscriptions(CommandFlags flags, object asyncState)
return last; return last;
} }
internal Task RemoveSubscription(RedisChannel channel, Action<RedisChannel, RedisValue> handler, CommandFlags flags, object asyncState) internal Task RemoveSubscription(in RedisChannel channel, Action<RedisChannel, RedisValue> handler, CommandFlags flags, object asyncState)
{ {
lock (subscriptions) lock (subscriptions)
{ {
...@@ -171,7 +171,7 @@ public ICompletable ForSyncShutdown() ...@@ -171,7 +171,7 @@ public ICompletable ForSyncShutdown()
var syncHandler = _syncHandler; var syncHandler = _syncHandler;
return syncHandler == null ? null : new MessageCompletable(default, default, syncHandler, null); return syncHandler == null ? null : new MessageCompletable(default, default, syncHandler, null);
} }
public ICompletable ForInvoke(RedisChannel channel, RedisValue message) public ICompletable ForInvoke(in RedisChannel channel, in RedisValue message)
{ {
var syncHandler = _syncHandler; var syncHandler = _syncHandler;
var asyncHandler = _asyncHandler; var asyncHandler = _asyncHandler;
...@@ -193,7 +193,7 @@ public bool Remove(bool asAsync, Action<RedisChannel, RedisValue> value) ...@@ -193,7 +193,7 @@ public bool Remove(bool asAsync, Action<RedisChannel, RedisValue> value)
return _syncHandler == null && _asyncHandler == null; return _syncHandler == null && _asyncHandler == null;
} }
public Task SubscribeToServer(ConnectionMultiplexer multiplexer, RedisChannel channel, CommandFlags flags, object asyncState, bool internalCall) public Task SubscribeToServer(ConnectionMultiplexer multiplexer, in RedisChannel channel, CommandFlags flags, object asyncState, bool internalCall)
{ {
var cmd = channel.IsPatternBased ? RedisCommand.PSUBSCRIBE : RedisCommand.SUBSCRIBE; var cmd = channel.IsPatternBased ? RedisCommand.PSUBSCRIBE : RedisCommand.SUBSCRIBE;
var selected = multiplexer.SelectServer(cmd, flags, default(RedisKey)); var selected = multiplexer.SelectServer(cmd, flags, default(RedisKey));
...@@ -205,7 +205,7 @@ public Task SubscribeToServer(ConnectionMultiplexer multiplexer, RedisChannel ch ...@@ -205,7 +205,7 @@ public Task SubscribeToServer(ConnectionMultiplexer multiplexer, RedisChannel ch
return selected.WriteDirectAsync(msg, ResultProcessor.TrackSubscriptions, asyncState); return selected.WriteDirectAsync(msg, ResultProcessor.TrackSubscriptions, asyncState);
} }
public Task UnsubscribeFromServer(RedisChannel channel, CommandFlags flags, object asyncState, bool internalCall) public Task UnsubscribeFromServer(in RedisChannel channel, CommandFlags flags, object asyncState, bool internalCall)
{ {
var oldOwner = Interlocked.Exchange(ref owner, null); var oldOwner = Interlocked.Exchange(ref owner, null);
if (oldOwner == null) return null; if (oldOwner == null) return null;
...@@ -218,7 +218,7 @@ public Task UnsubscribeFromServer(RedisChannel channel, CommandFlags flags, obje ...@@ -218,7 +218,7 @@ public Task UnsubscribeFromServer(RedisChannel channel, CommandFlags flags, obje
internal ServerEndPoint GetOwner() => Volatile.Read(ref owner); internal ServerEndPoint GetOwner() => Volatile.Read(ref owner);
internal void Resubscribe(RedisChannel channel, ServerEndPoint server) internal void Resubscribe(in RedisChannel channel, ServerEndPoint server)
{ {
if (server != null && Interlocked.CompareExchange(ref owner, server, server) == server) if (server != null && Interlocked.CompareExchange(ref owner, server, server) == server)
{ {
...@@ -229,7 +229,7 @@ internal void Resubscribe(RedisChannel channel, ServerEndPoint server) ...@@ -229,7 +229,7 @@ internal void Resubscribe(RedisChannel channel, ServerEndPoint server)
} }
} }
internal bool Validate(ConnectionMultiplexer multiplexer, RedisChannel channel) internal bool Validate(ConnectionMultiplexer multiplexer, in RedisChannel channel)
{ {
bool changed = false; bool changed = false;
var oldOwner = Volatile.Read(ref owner); var oldOwner = Volatile.Read(ref owner);
......
...@@ -122,7 +122,7 @@ public RespCommand(RedisCommandAttribute attrib, MethodInfo method, RespServer s ...@@ -122,7 +122,7 @@ public RespCommand(RedisCommandAttribute attrib, MethodInfo method, RespServer s
public bool HasSubCommands => _subcommands != null; public bool HasSubCommands => _subcommands != null;
internal RespCommand WithSubCommands(RespCommand[] subs) internal RespCommand WithSubCommands(RespCommand[] subs)
=> new RespCommand(this, subs); => new RespCommand(this, subs);
private RespCommand(RespCommand parent, RespCommand[] subs) private RespCommand(in RespCommand parent, RespCommand[] subs)
{ {
if (parent.IsSubCommand) throw new InvalidOperationException("Cannot have nested sub-commands"); if (parent.IsSubCommand) throw new InvalidOperationException("Cannot have nested sub-commands");
if (parent.HasSubCommands) throw new InvalidOperationException("Already has sub-commands"); if (parent.HasSubCommands) throw new InvalidOperationException("Already has sub-commands");
...@@ -155,7 +155,7 @@ public RespCommand Resolve(in RedisRequest request) ...@@ -155,7 +155,7 @@ public RespCommand Resolve(in RedisRequest request)
} }
return this; return this;
} }
public TypedRedisValue Execute(RedisClient client, RedisRequest request) public TypedRedisValue Execute(RedisClient client, in RedisRequest request)
{ {
var args = request.Count; var args = request.Count;
if (!CheckArity(request.Count)) if (!CheckArity(request.Count))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment