Commit 3fd054da authored by Nick Craver's avatar Nick Craver

Code cleanup

parent 9584d15b
...@@ -118,7 +118,7 @@ public void Dispose() ...@@ -118,7 +118,7 @@ public void Dispose()
{ {
var ioPipe = _ioPipe; var ioPipe = _ioPipe;
_ioPipe = null; _ioPipe = null;
if(ioPipe != null) if (ioPipe != null)
{ {
Multiplexer.Trace("Disconnecting...", physicalName); Multiplexer.Trace("Disconnecting...", physicalName);
try { ioPipe.Input?.CancelPendingRead(); } catch { } try { ioPipe.Input?.CancelPendingRead(); } catch { }
...@@ -424,7 +424,7 @@ internal void Write(RedisChannel channel) ...@@ -424,7 +424,7 @@ internal void Write(RedisChannel channel)
internal void Write(RedisValue value) internal void Write(RedisValue value)
{ {
switch(value.Type) switch (value.Type)
{ {
case RedisValue.StorageType.Null: case RedisValue.StorageType.Null:
WriteUnified(_ioPipe.Output, (byte[])null); WriteUnified(_ioPipe.Output, (byte[])null);
...@@ -681,7 +681,7 @@ internal void WriteSha1AsHex(byte[] value) ...@@ -681,7 +681,7 @@ internal void WriteSha1AsHex(byte[] value)
{ {
writer.Write(NullBulkString); writer.Write(NullBulkString);
} }
else if(value.Length == ResultProcessor.ScriptLoadProcessor.Sha1HashLength) else if (value.Length == ResultProcessor.ScriptLoadProcessor.Sha1HashLength)
{ {
// $40\r\n = 5 // $40\r\n = 5
// {40 bytes}\r\n = 42 // {40 bytes}\r\n = 42
...@@ -694,7 +694,7 @@ internal void WriteSha1AsHex(byte[] value) ...@@ -694,7 +694,7 @@ internal void WriteSha1AsHex(byte[] value)
span[4] = (byte)'\n'; span[4] = (byte)'\n';
int offset = 5; int offset = 5;
for(int i = 0; i < value.Length; i++) for (int i = 0; i < value.Length; i++)
{ {
var b = value[i]; var b = value[i];
span[offset++] = ToHexNibble(value[i] >> 4); span[offset++] = ToHexNibble(value[i] >> 4);
...@@ -790,7 +790,7 @@ private unsafe void WriteRaw(PipeWriter writer, string value, int expectedLength ...@@ -790,7 +790,7 @@ private unsafe void WriteRaw(PipeWriter writer, string value, int expectedLength
charOffset += charsUsed; charOffset += charsUsed;
charsRemaining -= charsUsed; charsRemaining -= charsUsed;
if(charsRemaining <= 0) if (charsRemaining <= 0)
{ {
if (charsRemaining < 0) throw new InvalidOperationException("String encode went negative"); if (charsRemaining < 0) throw new InvalidOperationException("String encode went negative");
if (completed) break; // fine if (completed) break; // fine
...@@ -1035,14 +1035,14 @@ void ISocketCallback.OnHeartbeat() ...@@ -1035,14 +1035,14 @@ void ISocketCallback.OnHeartbeat()
// note: TryRead will give us back the same buffer in a tight loop // note: TryRead will give us back the same buffer in a tight loop
// - so: only use that if we're making progress // - so: only use that if we're making progress
if(!(allowSyncRead && input.TryRead(out var readResult))) if (!(allowSyncRead && input.TryRead(out var readResult)))
{ {
readResult = await input.ReadAsync(); readResult = await input.ReadAsync();
} }
var buffer = readResult.Buffer; var buffer = readResult.Buffer;
int handled = 0; int handled = 0;
if(!buffer.IsEmpty) if (!buffer.IsEmpty)
{ {
handled = ProcessBuffer(ref buffer); // updates buffer.Start handled = ProcessBuffer(ref buffer); // updates buffer.Start
} }
...@@ -1177,9 +1177,9 @@ private RawResult ReadBulkString(in ReadOnlySequence<byte> buffer, ref BufferRea ...@@ -1177,9 +1177,9 @@ private RawResult ReadBulkString(in ReadOnlySequence<byte> buffer, ref BufferRea
return new RawResult(ResultType.BulkString, ReadOnlySequence<byte>.Empty, true); return new RawResult(ResultType.BulkString, ReadOnlySequence<byte>.Empty, true);
} }
if(reader.TryConsumeAsBuffer(bodySize, out var payload)) if (reader.TryConsumeAsBuffer(bodySize, out var payload))
{ {
switch(reader.TryConsumeCRLF()) switch (reader.TryConsumeCRLF())
{ {
case ConsumeResult.NeedMoreData: case ConsumeResult.NeedMoreData:
break; // see NilResult below break; // see NilResult below
...@@ -1285,7 +1285,7 @@ public BufferReader(ReadOnlySequence<byte> buffer) ...@@ -1285,7 +1285,7 @@ public BufferReader(ReadOnlySequence<byte> buffer)
/// </summary> /// </summary>
public ConsumeResult TryConsumeCRLF() public ConsumeResult TryConsumeCRLF()
{ {
switch(RemainingThisSpan) switch (RemainingThisSpan)
{ {
case 0: case 0:
return ConsumeResult.NeedMoreData; return ConsumeResult.NeedMoreData;
...@@ -1328,13 +1328,13 @@ public bool TryConsume(int count) ...@@ -1328,13 +1328,13 @@ public bool TryConsume(int count)
return false; return false;
} }
readonly ReadOnlySequence<byte> _buffer; private readonly ReadOnlySequence<byte> _buffer;
SequencePosition _lastSnapshotPosition; private SequencePosition _lastSnapshotPosition;
long _lastSnapshotBytes; private long _lastSnapshotBytes;
// makes an internal note of where we are, as a SequencePosition; useful // makes an internal note of where we are, as a SequencePosition; useful
// to avoid having to use buffer.Slice on huge ranges // to avoid having to use buffer.Slice on huge ranges
SequencePosition SnapshotPosition() private SequencePosition SnapshotPosition()
{ {
var consumed = TotalConsumed; var consumed = TotalConsumed;
var delta = consumed - _lastSnapshotBytes; var delta = consumed - _lastSnapshotBytes;
...@@ -1346,7 +1346,7 @@ SequencePosition SnapshotPosition() ...@@ -1346,7 +1346,7 @@ SequencePosition SnapshotPosition()
} }
public ReadOnlySequence<byte> ConsumeAsBuffer(int count) public ReadOnlySequence<byte> ConsumeAsBuffer(int count)
{ {
if(!TryConsumeAsBuffer(count, out var buffer)) throw new EndOfStreamException(); if (!TryConsumeAsBuffer(count, out var buffer)) throw new EndOfStreamException();
return buffer; return buffer;
} }
...@@ -1380,7 +1380,7 @@ public void Consume(int count) ...@@ -1380,7 +1380,7 @@ public void Consume(int count)
var span = reader.SlicedSpan; var span = reader.SlicedSpan;
if (haveTrailingCR) if (haveTrailingCR)
{ {
if(span[0] == '\n') return totalSkipped - 1; if (span[0] == '\n') return totalSkipped - 1;
haveTrailingCR = false; haveTrailingCR = false;
} }
......
...@@ -655,7 +655,7 @@ private sealed class KeyMigrateCommandMessage : Message.CommandKeyBase // MIGRAT ...@@ -655,7 +655,7 @@ private sealed class KeyMigrateCommandMessage : Message.CommandKeyBase // MIGRAT
private readonly MigrateOptions migrateOptions; private readonly MigrateOptions migrateOptions;
private readonly int timeoutMilliseconds; private readonly int timeoutMilliseconds;
private readonly int toDatabase; private readonly int toDatabase;
private RedisValue toHost, toPort; private readonly RedisValue toHost, toPort;
public KeyMigrateCommandMessage(int db, RedisKey key, EndPoint toServer, int toDatabase, int timeoutMilliseconds, MigrateOptions migrateOptions, CommandFlags flags) public KeyMigrateCommandMessage(int db, RedisKey key, EndPoint toServer, int toDatabase, int timeoutMilliseconds, MigrateOptions migrateOptions, CommandFlags flags)
: base(db, flags, RedisCommand.MIGRATE, key) : base(db, flags, RedisCommand.MIGRATE, key)
......
...@@ -608,7 +608,7 @@ private static string ToHex(ReadOnlySpan<byte> src) ...@@ -608,7 +608,7 @@ private static string ToHex(ReadOnlySpan<byte> src)
const string HexValues = "0123456789ABCDEF"; const string HexValues = "0123456789ABCDEF";
if (src.IsEmpty) return ""; if (src.IsEmpty) return "";
var s = new string((char)0, src.Length * 3 - 1); var s = new string((char)0, (src.Length * 3) - 1);
var dst = MemoryMarshal.AsMemory(s.AsMemory()).Span; var dst = MemoryMarshal.AsMemory(s.AsMemory()).Span;
int i = 0; int i = 0;
......
...@@ -1333,7 +1333,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes ...@@ -1333,7 +1333,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
internal sealed class SingleStreamProcessor : StreamProcessorBase<RedisStreamEntry[]> internal sealed class SingleStreamProcessor : StreamProcessorBase<RedisStreamEntry[]>
{ {
private bool skipStreamName; private readonly bool skipStreamName;
public SingleStreamProcessor(bool skipStreamName = false) public SingleStreamProcessor(bool skipStreamName = false)
{ {
...@@ -1454,7 +1454,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes ...@@ -1454,7 +1454,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
return true; return true;
} }
} }
static T[] ConvertAll<T>(ReadOnlySpan<RawResult> items, Func<RawResult, T> converter) private static T[] ConvertAll<T>(ReadOnlySpan<RawResult> items, Func<RawResult, T> converter)
{ {
if (items.Length == 0) return Array.Empty<T>(); if (items.Length == 0) return Array.Empty<T>();
T[] arr = new T[items.Length]; T[] arr = new T[items.Length];
......
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