Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
major, so this is not a lagging pin to be bumped to 3.x/4.x when the others are refreshed -->
<PackageVersion Include="StackExchange.Redis" Version="2.13.17" />
<PackageVersion Include="StackExchange.Redis.StrongName" Version="1.2.6" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.3.151-beta" />
<PackageVersion Include="System.Collections.Immutable" Version="10.0.13" />
<PackageVersion Include="System.Reflection.Metadata" Version="10.0.13" />
<!-- For binding redirect testing, main package gets this transitively -->
Expand Down
12 changes: 3 additions & 9 deletions src/RESPite.Benchmark/BenchmarkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,13 @@ private static string GetNameCore(Delegate underlyingAction, out string descript
{
string name = underlyingAction.Method.Name;

if (underlyingAction.Method.GetCustomAttribute(typeof(DisplayNameAttribute)) is DisplayNameAttribute
{
DisplayName: { Length: > 0 }
} dna)
if (underlyingAction.Method.GetCustomAttribute(typeof(DisplayNameAttribute)) is DisplayNameAttribute { DisplayName: { Length: > 0 } } dna)
{
name = dna.DisplayName;
}

description = "";
if (underlyingAction.Method.GetCustomAttribute(typeof(DescriptionAttribute)) is DescriptionAttribute
{
Description: { Length: > 0 }
} da)
if (underlyingAction.Method.GetCustomAttribute(typeof(DescriptionAttribute)) is DescriptionAttribute { Description: { Length: > 0 } } da)
{
description = da.Description;
}
Expand Down Expand Up @@ -568,7 +562,7 @@ private async Task RunAsyncCore<T>(
$"{TotalOperations(divisor):###,###,##0} requests completed in {seconds:0.00} seconds, {rate:###,###,##0} ops/sec");
}

if (!Quiet & typeof(T) != typeof(DBNull))
if (!Quiet & (typeof(T) != typeof(DBNull)))
{
const string format = "Typical result: {0}";

Expand Down
14 changes: 7 additions & 7 deletions src/RESPite/Buffers/CycleBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void CopyDueToDiscardDuringWrite(int count)
.CopyTo(full.Slice(targetOffset, count));
}
}
public bool CommittedIsEmpty => ReferenceEquals(startSegment, endSegment) & endSegmentCommitted == 0;
public bool CommittedIsEmpty => ReferenceEquals(startSegment, endSegment) & (endSegmentCommitted == 0);

/// <summary>
/// Marks committed data as fully consumed; it will no longer appear in later calls to <see cref="GetAllCommitted"/>.
Expand All @@ -117,8 +117,8 @@ public void DiscardCommitted(int count)

// optimize for most common case, where we consume everything
if (ReferenceEquals(startSegment, endSegment)
& count == endSegmentCommitted
& count > 0)
& (count == endSegmentCommitted)
& (count > 0))
{
/*
we are consuming all the data in the single segment; we can
Expand All @@ -144,8 +144,8 @@ public void DiscardCommitted(long count)

// optimize for most common case, where we consume everything
if (ReferenceEquals(startSegment, endSegment)
& count == endSegmentCommitted
& count > 0) // checks sign *and* non-trimmed
& (count == endSegmentCommitted)
& (count > 0)) // checks sign *and* non-trimmed
{
// see <see cref="DiscardCommitted(int)"/> for logic
endSegmentCommitted = 0;
Expand Down Expand Up @@ -339,7 +339,7 @@ public bool TryGetFirstCommittedMemory(int minBytes, out ReadOnlyMemory<byte> me

// partial segment (and we know it isn't empty)
memory = memory.Slice(start: 0, length: available);
return available >= minBytes & minBytes > 0; // last check here applies the -ve logic
return (available >= minBytes) & (minBytes > 0); // last check here applies the -ve logic
}

// multi-page; hand out the first page (which is, by definition: full)
Expand Down Expand Up @@ -603,7 +603,7 @@ public int Untrim(bool expandBackwards = false)
{
_flags &= ~(Flags.StartTrim | Flags.EndTrim);
Memory = fullMemory;
if (expandBackwards & RunningIndex >= delta)
if (expandBackwards & (RunningIndex >= delta))
{
// push our origin earlier; only valid if
// we're the first segment, otherwise
Expand Down
8 changes: 4 additions & 4 deletions src/RESPite/Internal/BlockBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public static BlockBuffer GetBuffer(BlockBufferSerializer parent, int sizeHint)
private int AvailableWithResetIfUseful()
{
if (_finalizedOffset != 0 // at least some chunks have been finalized
&& Volatile.Read(ref _refCount) == 1 // all finalized chunks returned
& _writeOffset == _finalizedOffset) // we're not in the middle of serializing something new
&& (Volatile.Read(ref _refCount) == 1) // all finalized chunks returned
& (_writeOffset == _finalizedOffset)) // we're not in the middle of serializing something new
{
_writeOffset = _finalizedOffset = 0; // swipe left
}
Expand Down Expand Up @@ -207,8 +207,8 @@ private void CopyFrom(Span<byte> source)

private bool TryResizeFor(int extraBytes)
{
if (_finalizedOffset == 0 & // we can only do this if there are no other messages in the buffer
Volatile.Read(ref _refCount) == 1) // and no-one else is looking (we already tried reset)
if ((_finalizedOffset == 0) & // we can only do this if there are no other messages in the buffer
(Volatile.Read(ref _refCount) == 1)) // and no-one else is looking (we already tried reset)
{
// we're already on the boundary - don't scrimp; just do the math from the end of the buffer
byte[] newArray = _arrayPool.Rent(_array.Length + extraBytes);
Expand Down
6 changes: 3 additions & 3 deletions src/RESPite/Messages/RespFrameScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static OperationStatus TryFastRead(ReadOnlySpan<byte> data, ref RespScan
lo = ((uint)UnsafeCpuUInt16(data, 4)) << 16;
break;
case 7:
lo = ((uint)UnsafeCpuUInt16(data, 4)) << 16 | ((uint)UnsafeCpuByte(data, 6)) << 8;
lo = (((uint)UnsafeCpuUInt16(data, 4)) << 16) | (((uint)UnsafeCpuByte(data, 6)) << 8);
break;
default:
lo = UnsafeCpuUInt32(data, 4);
Expand All @@ -123,7 +123,7 @@ private static OperationStatus TryFastRead(ReadOnlySpan<byte> data, ref RespScan
/// </summary>
public OperationStatus TryRead(ref RespScanState state, in ReadOnlySequence<byte> data)
{
if (!_pubsub & state.TotalBytes == 0 & data.IsSingleSegment)
if (!_pubsub & (state.TotalBytes == 0) & data.IsSingleSegment)
{
var status = TryFastRead(data.FirstSpan, ref state);
if (status != UseReader) return status;
Expand All @@ -148,7 +148,7 @@ static OperationStatus TryReadViaReader(ref RespScanState state, in ReadOnlySequ
/// </summary>
public OperationStatus TryRead(ref RespScanState state, ReadOnlySpan<byte> data)
{
if (!_pubsub & state.TotalBytes == 0)
if (!_pubsub & (state.TotalBytes == 0))
{
#if NET
var status = TryFastRead(data, ref state);
Expand Down
2 changes: 1 addition & 1 deletion src/RESPite/Messages/RespReader.Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public readonly byte[] Serialize()
target = target.Slice(span.Length);
if (!reader.TryMoveToNextSegment()) break;
}
if (remaining != 0 | !target.IsEmpty) ThrowEof();
if ((remaining != 0) | !target.IsEmpty) ThrowEof();
return arr;
}
}
20 changes: 11 additions & 9 deletions src/RESPite/Messages/RespReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ private readonly bool ScalarLengthIsSlow(int expected)
/// the <see cref="AggregateChildren"/> API, using the <see cref="RespReader.AggregateEnumerator.MovePast(out RespReader)"/> API to update the outer reader.</remarks>
public readonly int AggregateLength() =>
(_flags & (RespFlags.IsAggregate | RespFlags.IsStreaming)) == RespFlags.IsAggregate
? _length : AggregateLengthSlow();
? _length
: AggregateLengthSlow();

/// <summary>
/// Indicates whether the number of child elements associated with an aggregate is exactly the specified <paramref name="count"/> value.
Expand All @@ -250,7 +251,8 @@ public readonly int AggregateLength() =>
/// i.e. a map of the form <c>%2\r\n...</c> will report <c>4</c> as the length.</remarks>
public readonly bool AggregateLengthIs(int count)
=> (_flags & (RespFlags.IsAggregate | RespFlags.IsStreaming)) == RespFlags.IsAggregate
? _length == count : AggregateLengthIsSlow(count);
? _length == count
: AggregateLengthIsSlow(count);

public delegate T Projection<out T>(ref RespReader value);

Expand Down Expand Up @@ -385,7 +387,7 @@ internal readonly bool IsNonNullAggregate
internal int Delta() =>
(_flags & (RespFlags.IsScalar | RespFlags.IsAggregate | RespFlags.IsStreaming | RespFlags.IsAttribute)) switch
{
RespFlags.IsScalar | RespFlags.IsAggregate=> -1, // null has this
RespFlags.IsScalar | RespFlags.IsAggregate => -1, // null has this
RespFlags.IsScalar => -1,
RespFlags.IsAggregate => _length - 1,
RespFlags.IsAggregate | RespFlags.IsAttribute => _length,
Expand Down Expand Up @@ -423,7 +425,7 @@ private bool TryReadNextSkipAttributes(bool skipStreamTerminator)
{
SkipChildren();
}
else if (skipStreamTerminator & Prefix is RespPrefix.StreamTerminator)
else if (skipStreamTerminator & (Prefix is RespPrefix.StreamTerminator))
{
// skip terminator
}
Expand All @@ -446,7 +448,7 @@ private bool TryReadNextProcessAttributes<T>(RespAttributeReader<T> respAttribut
{
respAttributeReader.Read(ref this, ref attributes);
}
else if (skipStreamTerminator & Prefix is RespPrefix.StreamTerminator)
else if (skipStreamTerminator & (Prefix is RespPrefix.StreamTerminator))
{
// skip terminator
}
Expand Down Expand Up @@ -1657,7 +1659,7 @@ internal readonly bool IsOK() // go mad with this, because it is used so often
if (TryGetSpan(out var span) && span.Length == 2)
{
var u16 = Unsafe.ReadUnaligned<ushort>(ref UnsafeCurrent);
return u16 == RespConstants.OKUInt16 | u16 == RespConstants.OKUInt16_LC;
return (u16 == RespConstants.OKUInt16) | (u16 == RespConstants.OKUInt16_LC);
}

return IsSlow(RespConstants.OKBytes, RespConstants.OKBytes_LC);
Expand Down Expand Up @@ -1893,7 +1895,7 @@ public readonly bool TryReadInt64(out long value)
var span = Buffer(stackalloc byte[RespConstants.MaxRawBytesInt64 + 1]);
if (span.Length <= RespConstants.MaxRawBytesInt64)
{
return Utf8Parser.TryParse(span, out value, out int bytes) & bytes == span.Length;
return Utf8Parser.TryParse(span, out value, out int bytes) & (bytes == span.Length);
}

value = 0;
Expand Down Expand Up @@ -1927,7 +1929,7 @@ public readonly bool TryReadInt32(out int value)
var span = Buffer(stackalloc byte[RespConstants.MaxRawBytesInt32 + 1]);
if (span.Length <= RespConstants.MaxRawBytesInt32)
{
return Utf8Parser.TryParse(span, out value, out int bytes) & bytes == span.Length;
return Utf8Parser.TryParse(span, out value, out int bytes) & (bytes == span.Length);
}

value = 0;
Expand Down Expand Up @@ -2015,7 +2017,7 @@ internal readonly bool UnsafeTryReadShortAscii(out string value, int maxLength =
foreach (var b in span)
{
// allow [SPACE]-thru-[DEL], plus CR/LF
if (!(b < 127 & (b >= 32 | (b is 12 or 13))))
if (!((b < 127) & ((b >= 32) | (b is 12 or 13))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/RESPite/Messages/RespScanState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private long ReadCore(ref RespReader reader, long startOffset = 0)
#if DEBUG
_elementCount++;
#endif
if (!reader.IsAttribute & _prefix == RespPrefix.None)
if (!reader.IsAttribute & (_prefix == RespPrefix.None))
{
_prefix = reader.Prefix;
}
Expand Down
2 changes: 2 additions & 0 deletions src/RESPite/PublicAPI/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
*REMOVED*[SER004]override RESPite.AsciiHash.Equals(object? other) -> bool
[SER004]override RESPite.AsciiHash.Equals(object? obj) -> bool
4 changes: 2 additions & 2 deletions src/RESPite/Shared/AsciiHash.Comparers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private CaseSensitiveComparer() { }
public bool Equals(AsciiHash x, AsciiHash y)
{
var len = x.Length;
return (len == y.Length & x._hashCS == y._hashCS)
return ((len == y.Length) & (x._hashCS == y._hashCS))
&& (len <= MaxBytesHashed || x.Span.SequenceEqual(y.Span));
}

Expand All @@ -28,7 +28,7 @@ private CaseInsensitiveComparer() { }
public bool Equals(AsciiHash x, AsciiHash y)
{
var len = x.Length;
return (len == y.Length & x._hashUC == y._hashUC)
return ((len == y.Length) & (x._hashUC == y._hashUC))
&& (len <= MaxBytesHashed || SequenceEqualsCI(x.Span, y.Span));
}

Expand Down
8 changes: 4 additions & 4 deletions src/RESPite/Shared/AsciiHash.Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public AsciiHash(string? value) : this(value is null ? [] : Encoding.ASCII.GetBy
public override string ToString() => _length == 0 ? "" : Encoding.ASCII.GetString(_arr, _index, _length);

/// <inheritdoc/>
public override bool Equals(object? other) => other is AsciiHash hash && Equals(hash);
public override bool Equals(object? obj) => obj is AsciiHash hash && Equals(hash);

/// <inheritdoc cref="Equals(object)" />
[CLSCompliant(false)]
public bool Equals(in AsciiHash other)
{
return (_length == other.Length & _hashCS == other._hashCS)
return ((_length == other.Length) & (_hashCS == other._hashCS))
&& (_length <= MaxBytesHashed || Span.SequenceEqual(other.Span));
}

Expand All @@ -65,15 +65,15 @@ public bool IsCS(ReadOnlySpan<byte> value)
{
var cs = HashCS(value);
var len = _length;
if (cs != _hashCS | value.Length != len) return false;
if ((cs != _hashCS) | (value.Length != len)) return false;
return len <= MaxBytesHashed || Span.SequenceEqual(value);
}

public bool IsCI(ReadOnlySpan<byte> value)
{
var uc = HashUC(value);
var len = _length;
if (uc != _hashUC | value.Length != len) return false;
if ((uc != _hashUC) | (value.Length != len)) return false;
return len <= MaxBytesHashed || SequenceEqualsCI(Span, value);
}

Expand Down
6 changes: 3 additions & 3 deletions src/RESPite/Shared/AsciiHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static unsafe bool SequenceEqualsCI(ReadOnlySpan<byte> first, ReadOnlySpa
{
byte x = firstPtr[i];
var xCI = x & CS_MASK;
if (xCI >= 'A' & xCI <= 'Z')
if ((xCI >= 'A') & (xCI <= 'Z'))
{
// alpha mismatch
if (xCI != (secondPtr[i] & CS_MASK)) return false;
Expand Down Expand Up @@ -171,7 +171,7 @@ public static unsafe bool SequenceEqualsCI(ReadOnlySpan<char> first, ReadOnlySpa
{
int x = (byte)firstPtr[i];
var xCI = x & CS_MASK;
if (xCI >= 'A' & xCI <= 'Z')
if ((xCI >= 'A') & (xCI <= 'Z'))
{
// alpha mismatch
if (xCI != (secondPtr[i] & CS_MASK)) return false;
Expand Down Expand Up @@ -206,7 +206,7 @@ public static unsafe bool SequenceEqualsCI(ReadOnlySpan<char> first, ReadOnlySpa
{
int x = (byte)firstPtr[i];
var xCI = x & CS_MASK;
if (xCI >= 'A' & xCI <= 'Z')
if ((xCI >= 'A') & (xCI <= 'Z'))
{
// alpha mismatch
if (xCI != (secondPtr[i] & CS_MASK)) return false;
Expand Down
15 changes: 12 additions & 3 deletions src/StackExchange.Redis/ArrayGrepRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ private void SetFlag(LocalFlags flag, bool value)
/// </summary>
public RedisArrayIndex? Start
{
get => GetFlag(LocalFlags.StartSpecified) ? _start : null;
get
{
return GetFlag(LocalFlags.StartSpecified) ? _start : null;
}
set
{
if (value.HasValue)
Expand All @@ -84,7 +87,10 @@ public RedisArrayIndex? Start
/// </summary>
public RedisArrayIndex? End
{
get => GetFlag(LocalFlags.EndSpecified) ? _end : null;
get
{
return GetFlag(LocalFlags.EndSpecified) ? _end : null;
}
set
{
if (value.HasValue)
Expand All @@ -110,7 +116,10 @@ public RedisArrayIndex? End
/// <remarks>Corresponds to the <c>LIMIT</c> parameter.</remarks>
public long? Limit
{
get => GetFlag(LocalFlags.LimitSpecified) ? _limit : null;
get
{
return GetFlag(LocalFlags.LimitSpecified) ? _limit : null;
}
set
{
if (value.HasValue)
Expand Down
Loading
Loading