Skip to content

Commit 88490d9

Browse files
committed
Replaced comparison with -1 w/ equivalent comparison to 0
This allows the cpu to fuse the compare and jump.
1 parent 0fe4e4c commit 88490d9

File tree

55 files changed

+105
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+105
-105
lines changed

src/Components/Endpoints/src/FormMapping/FormDataReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ internal IReadOnlyDictionary<FormKey, HashSet<FormKey>> ProcessFormKeys()
138138
while (startIndex >= 0)
139139
{
140140
var endIndex = key.Value.Span[startIndex..].IndexOf(']') + startIndex;
141-
if (endIndex == -1)
141+
if (endIndex < 0)
142142
{
143143
// Ignore malformed keys
144144
break;
@@ -157,7 +157,7 @@ internal IReadOnlyDictionary<FormKey, HashSet<FormKey>> ProcessFormKeys()
157157

158158
var nextOpenBracket = key.Value.Span[(endIndex + 1)..].IndexOf('[');
159159

160-
startIndex = nextOpenBracket != -1 ? endIndex + 1 + nextOpenBracket : -1;
160+
startIndex = nextOpenBracket >= 0 ? endIndex + 1 + nextOpenBracket : -1;
161161
}
162162
}
163163

@@ -264,7 +264,7 @@ internal readonly bool TryGetValues(out StringValues values) =>
264264
internal string GetLastPrefixSegment()
265265
{
266266
var index = _currentPrefixBuffer.Span.LastIndexOfAny(".[");
267-
if (index == -1)
267+
if (index < 0)
268268
{
269269
return _currentPrefixBuffer.ToString();
270270
}

src/Components/Server/src/Circuits/ServerComponentDeserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public bool TryDeserializeComponentDescriptorCollection(string serializedCompone
113113
// check covers that the sequence starts by 0.
114114
if (lastSequence != serverComponent.Sequence - 1)
115115
{
116-
if (lastSequence == -1)
116+
if (lastSequence < 0)
117117
{
118118
Log.DescriptorSequenceMustStartAtZero(_logger, serverComponent.Sequence);
119119
}
@@ -125,7 +125,7 @@ public bool TryDeserializeComponentDescriptorCollection(string serializedCompone
125125
return false;
126126
}
127127

128-
if (lastSequence != -1 && !previousInstance.InvocationId.Equals(serverComponent.InvocationId))
128+
if (lastSequence >= 0 && !previousInstance.InvocationId.Equals(serverComponent.InvocationId))
129129
{
130130
Log.MismatchedInvocationId(_logger, previousInstance.InvocationId.ToString("N"), serverComponent.InvocationId.ToString("N"));
131131
descriptors.Clear();

src/DataProtection/DataProtection/src/TypeForwardingActivator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ protected static string RemoveVersionFromAssemblyName(string forwardedTypeName)
7979
// Type, Assembly, Version={Version}, Culture={Culture}, PublicKeyToken={Token}
8080

8181
var versionStartIndex = forwardedTypeName.IndexOf(", Version=", StringComparison.Ordinal);
82-
while (versionStartIndex != -1)
82+
while (versionStartIndex >= 0)
8383
{
8484
var versionEndIndex = forwardedTypeName.IndexOf(',', versionStartIndex + ", Version=".Length);
8585

86-
if (versionEndIndex == -1)
86+
if (versionEndIndex < 0)
8787
{
8888
// No end index, so are done and can remove the rest
8989
return forwardedTypeName.Substring(0, versionStartIndex);

src/DefaultBuilder/src/WebApplicationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ sourceValue is List<string> sourceDescriptions &&
501501
destinationValue is List<string> destinationDescriptions)
502502
{
503503
var wireUpIndex = destinationDescriptions.IndexOf(typeof(WireSourcePipeline).FullName!);
504-
if (wireUpIndex != -1)
504+
if (wireUpIndex >= 0)
505505
{
506506
destinationDescriptions.RemoveAt(wireUpIndex);
507507
destinationDescriptions.InsertRange(wireUpIndex, sourceDescriptions);

src/FileProviders/Embedded/src/EmbeddedFileProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public IChangeToken Watch(string pattern)
180180

181181
private static bool HasInvalidPathChars(string path)
182182
{
183-
return path.IndexOfAny(_invalidFileNameChars) != -1;
183+
return path.IndexOfAny(_invalidFileNameChars) >= 0;
184184
}
185185

186186
#region Helper methods

src/FileProviders/Embedded/src/Manifest/EmbeddedFilesManifest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ internal EmbeddedFilesManifest(ManifestDirectory rootDirectory)
6363
private static StringSegment RemoveLeadingAndTrailingDirectorySeparators(string path)
6464
{
6565
Debug.Assert(path.Length > 0);
66-
var start = Array.IndexOf(_separators, path[0]) == -1 ? 0 : 1;
66+
var start = Array.IndexOf(_separators, path[0]) < 0 ? 0 : 1;
6767
if (start == path.Length)
6868
{
6969
return StringSegment.Empty;
7070
}
7171

72-
var end = Array.IndexOf(_separators, path[path.Length - 1]) == -1 ? path.Length : path.Length - 1;
72+
var end = Array.IndexOf(_separators, path[path.Length - 1]) < 0 ? path.Length : path.Length - 1;
7373
var trimmed = new StringSegment(path, start, end - start);
7474
return trimmed;
7575
}
@@ -84,5 +84,5 @@ internal EmbeddedFilesManifest Scope(string path)
8484
throw new InvalidOperationException($"Invalid path: '{path}'");
8585
}
8686

87-
private static bool HasInvalidPathChars(string path) => path.IndexOfAny(_invalidFileNameChars) != -1;
87+
private static bool HasInvalidPathChars(string path) => path.IndexOfAny(_invalidFileNameChars) >= 0;
8888
}

src/Http/Headers/src/ContentDispositionHeaderValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ private StringSegment EncodeAndQuoteMime(StringSegment input)
487487

488488
if (needsQuotes)
489489
{
490-
if (result.IndexOfAny(EscapeChars) != -1)
490+
if (result.IndexOfAny(EscapeChars) >= 0)
491491
{
492492
// '\' and '"' must be escaped in a quoted string
493493
result = result.ToString().Replace(@"\", @"\\").Replace(@"""", @"\""");

src/Http/Headers/src/HeaderUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private static int AdvanceCacheDirectiveIndex(int current, string headerValue)
196196
// Find the next delimiter
197197
current = headerValue.IndexOf(',', current);
198198

199-
if (current == -1)
199+
if (current < 0)
200200
{
201201
// If no delimiter found, skip to the end
202202
return headerValue.Length;

src/Http/Headers/src/MediaTypeHeaderValue.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public StringSegment SubTypeWithoutSuffix
278278
{
279279
var subType = SubType;
280280
var startOfSuffix = subType.LastIndexOf(PlusCharacter);
281-
if (startOfSuffix == -1)
281+
if (startOfSuffix < 0)
282282
{
283283
return subType;
284284
}
@@ -303,7 +303,7 @@ public StringSegment Suffix
303303
{
304304
var subType = SubType;
305305
var startOfSuffix = subType.LastIndexOf(PlusCharacter);
306-
if (startOfSuffix == -1)
306+
if (startOfSuffix < 0)
307307
{
308308
return default(StringSegment);
309309
}
@@ -718,7 +718,7 @@ private bool MatchesSubtype(StringSegment mediaType)
718718

719719
StringSegment suffix;
720720
var startOfSuffix = subType.LastIndexOf(PlusCharacter);
721-
if (startOfSuffix == -1)
721+
if (startOfSuffix < 0)
722722
{
723723
suffix = default(StringSegment);
724724
}
@@ -756,7 +756,7 @@ private bool MatchesSubtypeWithoutSuffix(MediaTypeHeaderValue set)
756756
private bool MatchesSubtypeWithoutSuffix(StringSegment subType, int startOfSuffix)
757757
{
758758
StringSegment subTypeWithoutSuffix;
759-
if (startOfSuffix == -1)
759+
if (startOfSuffix < 0)
760760
{
761761
subTypeWithoutSuffix = subType;
762762
}

src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public bool MoveNext()
141141
_trailingStart = -1;
142142

143143
if (_offset == _headerLength &&
144-
_leadingStart != -1 &&
144+
_leadingStart >= 0 &&
145145
_leadingStart != _offset)
146146
{
147147
// Also produce trailing whitespace
@@ -186,9 +186,9 @@ public bool MoveNext()
186186
switch (attr)
187187
{
188188
case Attr.Delimiter:
189-
_valueStart = _valueStart == -1 ? _offset : _valueStart;
190-
_valueEnd = _valueEnd == -1 ? _offset : _valueEnd;
191-
_trailingStart = _trailingStart == -1 ? _offset : _trailingStart;
189+
_valueStart = _valueStart < 0 ? _offset : _valueStart;
190+
_valueEnd = _valueEnd < 0 ? _offset : _valueEnd;
191+
_trailingStart = _trailingStart < 0 ? _offset : _trailingStart;
192192
_leadingEnd = _offset;
193193
_mode = Mode.Produce;
194194
break;

0 commit comments

Comments
 (0)