Commit 532fc4f4 authored by Nick Craver's avatar Nick Craver

Cleanup: spacing/access modifiers

parent 86039446
...@@ -45,6 +45,9 @@ dotnet_style_coalesce_expression = true:suggestion ...@@ -45,6 +45,9 @@ dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion dotnet_style_explicit_tuple_names = true:suggestion
# Ignore silly if statements
dotnet_style_prefer_conditional_expression_over_return = false:none
# CSharp code style settings: # CSharp code style settings:
[*.cs] [*.cs]
# Prefer method-like constructs to have a expression-body # Prefer method-like constructs to have a expression-body
...@@ -74,3 +77,6 @@ csharp_new_line_before_members_in_anonymous_types = true ...@@ -74,3 +77,6 @@ csharp_new_line_before_members_in_anonymous_types = true
# Space settings # Space settings
csharp_space_after_keywords_in_control_flow_statements = true:suggestion csharp_space_after_keywords_in_control_flow_statements = true:suggestion
# Language settings
csharp_prefer_simple_default_expression = false:none
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for StackOverflow" Description="Code analysis rules for the StackOverflow solution." ToolsVersion="15.0"> <RuleSet Name="Rules for StackOverflow" Description="Code analysis rules for the StackOverflow solution." ToolsVersion="15.0">
<IncludeAll Action="Warning" /> <IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
<Rule Id="IDE0045" Action="None" />
<Rule Id="IDE0046" Action="None" />
</Rules>
<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers"> <Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
<Rule Id="RCS1047" Action="None" />
<Rule Id="RCS1057" Action="None" /> <Rule Id="RCS1057" Action="None" />
<Rule Id="RCS1154" Action="None" />
</Rules> </Rules>
</RuleSet> </RuleSet>
\ No newline at end of file
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly: TypeForwardedTo(typeof(global::StackExchange.Redis.Aggregate))] [assembly: TypeForwardedTo(typeof(global::StackExchange.Redis.Aggregate))]
[assembly: TypeForwardedTo(typeof(global::StackExchange.Redis.Bitwise))] [assembly: TypeForwardedTo(typeof(global::StackExchange.Redis.Bitwise))]
[assembly: TypeForwardedTo(typeof(global::StackExchange.Redis.ClientFlags))] [assembly: TypeForwardedTo(typeof(global::StackExchange.Redis.ClientFlags))]
......
...@@ -31,7 +31,6 @@ public void NullWorks() ...@@ -31,7 +31,6 @@ public void NullWorks()
[Fact] [Fact]
public void DefaultWorks() public void DefaultWorks()
{ {
var result = default(RawResult); var result = default(RawResult);
Assert.Equal(ResultType.None, result.Type); Assert.Equal(ResultType.None, result.Type);
Assert.True(result.IsNull); Assert.True(result.IsNull);
...@@ -49,7 +48,6 @@ public void DefaultWorks() ...@@ -49,7 +48,6 @@ public void DefaultWorks()
[Fact] [Fact]
public void NilWorks() public void NilWorks()
{ {
var result = RawResult.Nil; var result = RawResult.Nil;
Assert.Equal(ResultType.None, result.Type); Assert.Equal(ResultType.None, result.Type);
Assert.True(result.IsNull); Assert.True(result.IsNull);
......
...@@ -143,12 +143,12 @@ void Check(RedisValue known, RedisValue test) ...@@ -143,12 +143,12 @@ void Check(RedisValue known, RedisValue test)
CheckString(double.PositiveInfinity, "+inf"); CheckString(double.PositiveInfinity, "+inf");
} }
static void CheckString(RedisValue value, string expected) private static void CheckString(RedisValue value, string expected)
{ {
var s = value.ToString(); var s = value.ToString();
Assert.True(s == expected, $"'{s}' vs '{expected}'"); Assert.True(s == expected, $"'{s}' vs '{expected}'");
} }
static byte[] Bytes(string s) => s == null ? null : Encoding.UTF8.GetBytes(s); private static byte[] Bytes(string s) => s == null ? null : Encoding.UTF8.GetBytes(s);
} }
} }
...@@ -183,7 +183,7 @@ internal static unsafe string DecodeUtf8(ReadOnlySpan<byte> s) ...@@ -183,7 +183,7 @@ internal static unsafe string DecodeUtf8(ReadOnlySpan<byte> s)
return Encoding.UTF8.GetString(ptr, s.Length); return Encoding.UTF8.GetString(ptr, s.Length);
} }
} }
static bool CaseInsensitiveASCIIEqual(string xLowerCase, ReadOnlySpan<byte> y) private static bool CaseInsensitiveASCIIEqual(string xLowerCase, ReadOnlySpan<byte> y)
{ {
if (y.Length != xLowerCase.Length) return false; if (y.Length != xLowerCase.Length) return false;
for(int i = 0; i < y.Length; i++) for(int i = 0; i < y.Length; i++)
......
...@@ -119,7 +119,7 @@ public WriteResult TryWrite(Message message, bool isSlave) ...@@ -119,7 +119,7 @@ public WriteResult TryWrite(Message message, bool isSlave)
// you can go in the queue, but we won't be starting // you can go in the queue, but we won't be starting
// a worker, because the handshake has not completed // a worker, because the handshake has not completed
var queue = _preconnectBacklog; var queue = _preconnectBacklog;
lock(queue) lock (queue)
{ {
queue.Enqueue(message); queue.Enqueue(message);
} }
...@@ -136,7 +136,6 @@ public WriteResult TryWrite(Message message, bool isSlave) ...@@ -136,7 +136,6 @@ public WriteResult TryWrite(Message message, bool isSlave)
var physical = this.physical; var physical = this.physical;
if (physical == null) return WriteResult.NoConnectionAvailable; if (physical == null) return WriteResult.NoConnectionAvailable;
var result = WriteMessageDirect(physical, message); var result = WriteMessageDirect(physical, message);
LogNonPreferred(message.Flags, isSlave); LogNonPreferred(message.Flags, isSlave);
...@@ -182,10 +181,11 @@ internal int GetOutstandingCount(out int inst, out int qs, out int qc, out int @ ...@@ -182,10 +181,11 @@ internal int GetOutstandingCount(out int inst, out int qs, out int qc, out int @
{// defined as: PendingUnsentItems + SentItemsAwaitingResponse + ResponsesAwaitingAsyncCompletion {// defined as: PendingUnsentItems + SentItemsAwaitingResponse + ResponsesAwaitingAsyncCompletion
inst = (int)(Interlocked.Read(ref operationCount) - Interlocked.Read(ref profileLastLog)); inst = (int)(Interlocked.Read(ref operationCount) - Interlocked.Read(ref profileLastLog));
var tmp = physical; var tmp = physical;
if(tmp == null) if (tmp == null)
{ {
qs = @in = 0; qs = @in = 0;
} else }
else
{ {
qs = tmp.GetSentAwaitingResponseCount(); qs = tmp.GetSentAwaitingResponseCount();
@in = tmp.GetAvailableInboundBytes(); @in = tmp.GetAvailableInboundBytes();
...@@ -257,7 +257,8 @@ internal async Task OnConnectedAsync(PhysicalConnection connection, TextWriter l ...@@ -257,7 +257,8 @@ internal async Task OnConnectedAsync(PhysicalConnection connection, TextWriter l
try try
{ {
connection.Dispose(); connection.Dispose();
} catch { } }
catch { }
} }
} }
...@@ -311,24 +312,24 @@ internal void OnDisconnected(ConnectionFailureType failureType, PhysicalConnecti ...@@ -311,24 +312,24 @@ internal void OnDisconnected(ConnectionFailureType failureType, PhysicalConnecti
private Message DequeueNextPendingBacklog() private Message DequeueNextPendingBacklog()
{ {
lock(_preconnectBacklog) lock (_preconnectBacklog)
{ {
return _preconnectBacklog.Count == 0 ? null : _preconnectBacklog.Dequeue(); return _preconnectBacklog.Count == 0 ? null : _preconnectBacklog.Dequeue();
} }
} }
void WritePendingBacklog(PhysicalConnection connection) private void WritePendingBacklog(PhysicalConnection connection)
{ {
if(connection != null) if (connection != null)
{ {
Message next; Message next;
do do
{ {
next = DequeueNextPendingBacklog(); next = DequeueNextPendingBacklog();
if(next != null) WriteMessageDirect(connection, next); if (next != null) WriteMessageDirect(connection, next);
} while (next != null); } while (next != null);
} }
} }
void AbandonPendingBacklog(Exception ex) private void AbandonPendingBacklog(Exception ex)
{ {
Message next; Message next;
do do
...@@ -394,7 +395,7 @@ internal void OnHeartbeat(bool ifConnectedOnly) ...@@ -394,7 +395,7 @@ internal void OnHeartbeat(bool ifConnectedOnly)
var tmp = physical; var tmp = physical;
if (tmp != null) if (tmp != null)
{ {
if(state == (int)State.ConnectedEstablished) if (state == (int)State.ConnectedEstablished)
{ {
Interlocked.Exchange(ref connectTimeoutRetryCount, 0); Interlocked.Exchange(ref connectTimeoutRetryCount, 0);
tmp.Bridge.ServerEndPoint.ClearUnselectable(UnselectableFlags.DidNotRespond); tmp.Bridge.ServerEndPoint.ClearUnselectable(UnselectableFlags.DidNotRespond);
...@@ -403,7 +404,7 @@ internal void OnHeartbeat(bool ifConnectedOnly) ...@@ -403,7 +404,7 @@ internal void OnHeartbeat(bool ifConnectedOnly)
int writeEverySeconds = ServerEndPoint.WriteEverySeconds, int writeEverySeconds = ServerEndPoint.WriteEverySeconds,
checkConfigSeconds = Multiplexer.RawConfig.ConfigCheckSeconds; checkConfigSeconds = Multiplexer.RawConfig.ConfigCheckSeconds;
if(state == (int)State.ConnectedEstablished && ConnectionType == ConnectionType.Interactive if (state == (int)State.ConnectedEstablished && ConnectionType == ConnectionType.Interactive
&& checkConfigSeconds > 0 && ServerEndPoint.LastInfoReplicationCheckSecondsAgo >= checkConfigSeconds && checkConfigSeconds > 0 && ServerEndPoint.LastInfoReplicationCheckSecondsAgo >= checkConfigSeconds
&& ServerEndPoint.CheckInfoReplication()) && ServerEndPoint.CheckInfoReplication())
{ {
...@@ -549,7 +550,7 @@ internal WriteResult WriteMessageDirect(PhysicalConnection physical, Message nex ...@@ -549,7 +550,7 @@ internal WriteResult WriteMessageDirect(PhysicalConnection physical, Message nex
} }
finally finally
{ {
if(haveLock) Monitor.Exit(WriteLock); if (haveLock) Monitor.Exit(WriteLock);
} }
return result; return result;
...@@ -710,7 +711,7 @@ private WriteResult WriteMessageToServer(PhysicalConnection connection, Message ...@@ -710,7 +711,7 @@ private WriteResult WriteMessageToServer(PhysicalConnection connection, Message
{ {
case RedisCommand.EVAL: case RedisCommand.EVAL:
case RedisCommand.EVALSHA: case RedisCommand.EVALSHA:
if(!ServerEndPoint.GetFeatures().ScriptingDatabaseSafe) if (!ServerEndPoint.GetFeatures().ScriptingDatabaseSafe)
{ {
connection.SetUnknownDatabase(); connection.SetUnknownDatabase();
} }
......
...@@ -467,7 +467,6 @@ internal void WriteHeader(string command, int arguments) ...@@ -467,7 +467,6 @@ internal void WriteHeader(string command, int arguments)
private void WriteHeader(byte[] commandBytes, int arguments) private void WriteHeader(byte[] commandBytes, int arguments)
{ {
// remember the time of the first write that still not followed by read // remember the time of the first write that still not followed by read
Interlocked.CompareExchange(ref firstUnansweredWriteTickCount, Environment.TickCount, 0); Interlocked.CompareExchange(ref firstUnansweredWriteTickCount, Environment.TickCount, 0);
......
...@@ -9,7 +9,6 @@ namespace StackExchange.Redis ...@@ -9,7 +9,6 @@ namespace StackExchange.Redis
internal static readonly RawResult NullMultiBulk = new RawResult(null, 0); internal static readonly RawResult NullMultiBulk = new RawResult(null, 0);
internal static readonly RawResult EmptyMultiBulk = new RawResult(Array.Empty<RawResult>(), 0); internal static readonly RawResult EmptyMultiBulk = new RawResult(Array.Empty<RawResult>(), 0);
internal static readonly RawResult Nil = default; internal static readonly RawResult Nil = default;
private readonly ReadOnlySequence<byte> _payload; private readonly ReadOnlySequence<byte> _payload;
// note: can't use Memory<RawResult> here - struct recursion breaks runtimr // note: can't use Memory<RawResult> here - struct recursion breaks runtimr
...@@ -17,7 +16,7 @@ namespace StackExchange.Redis ...@@ -17,7 +16,7 @@ namespace StackExchange.Redis
private readonly int _itemsCount; private readonly int _itemsCount;
private readonly ResultType _type; private readonly ResultType _type;
const ResultType NonNullFlag = (ResultType)128; private const ResultType NonNullFlag = (ResultType)128;
public RawResult(ResultType resultType, ReadOnlySequence<byte> payload, bool isNull) public RawResult(ResultType resultType, ReadOnlySequence<byte> payload, bool isNull)
{ {
...@@ -84,7 +83,6 @@ internal RedisChannel AsRedisChannel(byte[] channelPrefix, RedisChannel.PatternM ...@@ -84,7 +83,6 @@ internal RedisChannel AsRedisChannel(byte[] channelPrefix, RedisChannel.PatternM
} }
if (AssertStarts(channelPrefix)) if (AssertStarts(channelPrefix))
{ {
byte[] copy = _payload.Slice(channelPrefix.Length).ToArray(); byte[] copy = _payload.Slice(channelPrefix.Length).ToArray();
return new RedisChannel(copy, mode); return new RedisChannel(copy, mode);
} }
...@@ -133,7 +131,7 @@ public void Recycle(int limit = -1) ...@@ -133,7 +131,7 @@ public void Recycle(int limit = -1)
arr[i].Recycle(); arr[i].Recycle();
} }
ArrayPool<RawResult>.Shared.Return(arr, clearArray: false); ArrayPool<RawResult>.Shared.Return(arr, clearArray: false);
} }
} }
internal unsafe bool IsEqual(byte[] expected) internal unsafe bool IsEqual(byte[] expected)
...@@ -341,7 +339,7 @@ internal unsafe string GetString() ...@@ -341,7 +339,7 @@ internal unsafe string GetString()
charCount += decoder.GetCharCount(bPtr, span.Length, false); charCount += decoder.GetCharCount(bPtr, span.Length, false);
} }
} }
decoder.Reset(); decoder.Reset();
string s = new string((char)0, charCount); string s = new string((char)0, charCount);
......
...@@ -146,7 +146,7 @@ public override bool Equals(object obj) ...@@ -146,7 +146,7 @@ public override bool Equals(object obj)
/// See Object.GetHashCode() /// See Object.GetHashCode()
/// </summary> /// </summary>
public override int GetHashCode() => GetHashCode(this); public override int GetHashCode() => GetHashCode(this);
static int GetHashCode(RedisValue x) private static int GetHashCode(RedisValue x)
{ {
x = x.Simplify(); x = x.Simplify();
switch (x.Type) switch (x.Type)
...@@ -309,7 +309,7 @@ internal StorageType Type ...@@ -309,7 +309,7 @@ internal StorageType Type
/// <param name="other">The other <see cref="RedisValue"/> to compare.</param> /// <param name="other">The other <see cref="RedisValue"/> to compare.</param>
public int CompareTo(RedisValue other) => CompareTo(this, other); public int CompareTo(RedisValue other) => CompareTo(this, other);
static int CompareTo(RedisValue x, RedisValue y) private static int CompareTo(RedisValue x, RedisValue y)
{ {
try try
{ {
...@@ -345,7 +345,6 @@ static int CompareTo(RedisValue x, RedisValue y) ...@@ -345,7 +345,6 @@ static int CompareTo(RedisValue x, RedisValue y)
break; break;
} }
// otherwise, compare as strings // otherwise, compare as strings
return string.CompareOrdinal((string)x, (string)y); return string.CompareOrdinal((string)x, (string)y);
} }
...@@ -455,8 +454,6 @@ internal static RedisValue TryParse(object obj) ...@@ -455,8 +454,6 @@ internal static RedisValue TryParse(object obj)
return new RedisValue(0, default, value); return new RedisValue(0, default, value);
} }
/// <summary> /// <summary>
/// Creates a new <see cref="RedisValue"/> from an <see cref="T:byte[]"/>. /// Creates a new <see cref="RedisValue"/> from an <see cref="T:byte[]"/>.
/// </summary> /// </summary>
...@@ -605,7 +602,7 @@ private static bool TryParseDouble(ReadOnlySpan<byte> blob, out double value) ...@@ -605,7 +602,7 @@ private static bool TryParseDouble(ReadOnlySpan<byte> blob, out double value)
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
} }
static string ToHex(ReadOnlySpan<byte> src) private static string ToHex(ReadOnlySpan<byte> src)
{ {
const string HexValues = "0123456789ABCDEF"; const string HexValues = "0123456789ABCDEF";
...@@ -742,7 +739,6 @@ private RedisValue Simplify() ...@@ -742,7 +739,6 @@ private RedisValue Simplify()
if (f64 >= long.MinValue && f64 <= long.MaxValue if (f64 >= long.MinValue && f64 <= long.MaxValue
&& (i64 = (long)f64) == f64) return i64; && (i64 = (long)f64) == f64) return i64;
break; break;
} }
return this; return this;
} }
......
...@@ -395,7 +395,6 @@ internal static bool IsSHA1(string script) ...@@ -395,7 +395,6 @@ internal static bool IsSHA1(string script)
return script != null && sha1.IsMatch(script); return script != null && sha1.IsMatch(script);
} }
internal const int Sha1HashLength = 20; internal const int Sha1HashLength = 20;
internal static byte[] ParseSHA1(byte[] value) internal static byte[] ParseSHA1(byte[] value)
{ {
......
...@@ -466,7 +466,7 @@ internal Task OnEstablishingAsync(PhysicalConnection connection, TextWriter log) ...@@ -466,7 +466,7 @@ internal Task OnEstablishingAsync(PhysicalConnection connection, TextWriter log)
} }
return Task.CompletedTask; return Task.CompletedTask;
} }
async Task OnEstablishingAsyncAwaited(PhysicalConnection connection, Task handshake) private async Task OnEstablishingAsyncAwaited(PhysicalConnection connection, Task handshake)
{ {
try try
{ {
......
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