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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static bool IsInSubtypeRelationshipWith(this Type type, Type other) =>
type.IsAssignableFromInternal(other) || other.IsAssignableFromInternal(type);

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() is not null;

public static bool HasRequiredMemberAttribute(this MemberInfo memberInfo)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,7 @@ public bool Pop()
private readonly bool PeekInArray()
{
int index = _currentDepth - AllocationFreeMaxDepth - 1;
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(index >= 0, $"Get - Negative - index: {index}, arrayLength: {_array.Length}");

int elementIndex = Div32Rem(index, out int extraBits);
Expand All@@ -161,7 +161,7 @@ public readonly bool Peek()

private void DoubleArray(int minSize)
{
Debug.Assert(_array != null);
Debug.Assert(_array is not null);
Debug.Assert(_array.Length < int.MaxValue / 2, $"Array too large - arrayLength: {_array.Length}");
Debug.Assert(minSize >= 0 && minSize >= _array.Length);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ internal readonly struct DbRow

internal DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
{
Debug.Assert(jsonTokenType > JsonTokenType.None && jsonTokenType <= JsonTokenType.Null);
Debug.Assert(jsonTokenType is > JsonTokenType.None and <= JsonTokenType.Null);
Debug.Assert((byte)jsonTokenType < 1 << 4);
Debug.Assert(location >= 0);
Debug.Assert(sizeOrLength >= UnknownSize);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,7 +130,7 @@ internal static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
// were more frequent anyways.
const int OneMegabyte = 1024 * 1024;

if (initialSize > OneMegabyte && initialSize <= 4 * OneMegabyte)
if (initialSize is > OneMegabyte and <= 4 * OneMegabyte)
{
initialSize = OneMegabyte;
}
Expand All@@ -151,7 +151,7 @@ internal static MetadataDb CreateLocked(int payloadLength)
public void Dispose()
{
byte[]? data = Interlocked.Exchange(ref _data, null!);
if (data == null)
if (data is null)
{
return;
}
Expand All@@ -175,7 +175,7 @@ internal void CompleteAllocations()
{
if (_convertToAlloc)
{
Debug.Assert(_data != null);
Debug.Assert(_data is not null);
byte[] returnBuf = _data;
_data = _data.AsSpan(0, Length).ToArray();
_isLocked = true;
Expand DownExpand Up@@ -217,7 +217,7 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length)
{
// StartArray or StartObject should have length -1, otherwise the length should not be -1.
Debug.Assert(
(tokenType == JsonTokenType.StartArray || tokenType == JsonTokenType.StartObject) ==
(tokenType is JsonTokenType.StartArray or JsonTokenType.StartObject) ==
(length == DbRow.UnknownSize));

if (Length >= _data.Length - DbRow.Size)
Expand DownExpand Up@@ -275,7 +275,7 @@ internal void SetLength(int index, int length)
internal void SetNumberOfRows(int index, int numberOfRows)
{
AssertValidIndex(index);
Debug.Assert(numberOfRows >= 1 && numberOfRows <= 0x0FFFFFFF);
Debug.Assert(numberOfRows is >= 1 and <= 0x0FFFFFFF);

Span<byte> dataPos = _data.AsSpan(index + NumberOfRowsOffset);
int current = MemoryMarshal.Read<int>(dataPos);
Expand All@@ -299,7 +299,7 @@ internal void SetHasComplexChildren(int index)

internal int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
{
Debug.Assert(lookupType == JsonTokenType.StartObject || lookupType == JsonTokenType.StartArray);
Debug.Assert(lookupType is JsonTokenType.StartObject or JsonTokenType.StartArray);
return FindOpenElement(lookupType);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options =
ArgumentNullException.ThrowIfNull(utf8Json);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand DownExpand Up@@ -154,10 +154,10 @@ internal static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDo

internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
{
Debug.Assert(utf8Json != null);
Debug.Assert(utf8Json is not null);

ArraySegment<byte> drained = ReadToEnd(utf8Json);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -185,7 +185,7 @@ internal static JsonDocument ParseValue(ReadOnlySpan<byte> utf8Json, JsonDocumen

internal static JsonDocument ParseValue(string json, JsonDocumentOptions options)
{
Debug.Assert(json != null);
Debug.Assert(json is not null);
return ParseValue(json.AsSpan(), options);
}

Expand DownExpand Up@@ -221,7 +221,7 @@ private static async Task<JsonDocument> ParseAsyncCore(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);
try
{
return Parse(
Expand All@@ -245,7 +245,7 @@ internal static async Task<JsonDocument> ParseAsyncCoreUnrented(
CancellationToken cancellationToken = default)
{
ArraySegment<byte> drained = await ReadToEndAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Debug.Assert(drained.Array != null);
Debug.Assert(drained.Array is not null);

byte[] owned = new byte[drained.Count];
Buffer.BlockCopy(drained.Array, 0, owned, 0, drained.Count);
Expand DownExpand Up@@ -439,7 +439,7 @@ internal static JsonDocument ParseValue(ref Utf8JsonReader reader, bool allowDup
bool ret = TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: true, allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document;
}

Expand DownExpand Up@@ -758,14 +758,12 @@ private static JsonDocument ParseUnrented(
{
// These tokens should already have been processed.
Debug.Assert(
tokenType != JsonTokenType.Null &&
tokenType != JsonTokenType.False &&
tokenType != JsonTokenType.True);
tokenType is not (JsonTokenType.Null or JsonTokenType.False or JsonTokenType.True));

ReadOnlySpan<byte> utf8JsonSpan = utf8Json.Span;
MetadataDb database;

if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
if (tokenType is JsonTokenType.String or JsonTokenType.Number)
{
// For primitive types, we can avoid renting MetadataDb and creating StackRowStack.
database = MetadataDb.CreateLocked(utf8Json.Length);
Expand DownExpand Up@@ -859,7 +857,7 @@ private static ArraySegment<byte> ReadToEnd(Stream stream)
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand DownExpand Up@@ -941,7 +939,7 @@ private static async
}
catch
{
if (rented != null)
if (rented is not null)
{
// Holds document content, clear it before returning it.
rented.AsSpan(0, written).Clear();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Dispose()
_rentedBuffer = null!;
_topOfStack = 0;

if (toReturn != null)
if (toReturn is not null)
{
// The data in this rented buffer only conveys the positions and
// lengths of tokens in a document, but no content; so it does not
Expand All@@ -52,7 +52,7 @@ internal void Push(StackRow row)

internal StackRow Pop()
{
Debug.Assert(_rentedBuffer != null);
Debug.Assert(_rentedBuffer is not null);
Debug.Assert(_topOfStack <= _rentedBuffer!.Length - StackRow.Size);

StackRow row = MemoryMarshal.Read<StackRow>(_rentedBuffer.AsSpan(_topOfStack));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ private unsafe bool TryGetNamedPropertyValue(
}
finally
{
if (rented != null)
if (rented is not null)
{
rented.AsSpan(0, written).Clear();
ArrayPool<byte>.Shared.Return(rented);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,10 +45,10 @@ private JsonDocument(

// Both rented values better be null if we're not disposable.
Debug.Assert(isDisposable ||
(extraRentedArrayPoolBytes == null && extraPooledByteBufferWriter == null));
(extraRentedArrayPoolBytes is null && extraPooledByteBufferWriter is null));

// Both rented values can't be specified.
Debug.Assert(extraRentedArrayPoolBytes == null || extraPooledByteBufferWriter == null);
Debug.Assert(extraRentedArrayPoolBytes is null || extraPooledByteBufferWriter is null);

_utf8Json = utf8Json;
_parsedData = parsedData;
Expand All@@ -69,19 +69,19 @@ public void Dispose()
_parsedData.Dispose();
_utf8Json = ReadOnlyMemory<byte>.Empty;

if (_extraRentedArrayPoolBytes != null)
if (_extraRentedArrayPoolBytes is not null)
{
byte[]? extraRentedBytes = Interlocked.Exchange<byte[]?>(ref _extraRentedArrayPoolBytes, null);

if (extraRentedBytes != null)
if (extraRentedBytes is not null)
{
// When "extra rented bytes exist" it contains the document,
// and thus needs to be cleared before being returned.
extraRentedBytes.AsSpan(0, length).Clear();
ArrayPool<byte>.Shared.Return(extraRentedBytes);
}
}
else if (_extraPooledByteBufferWriter != null)
else if (_extraPooledByteBufferWriter is not null)
{
PooledByteBufferWriter? extraBufferWriter = Interlocked.Exchange<PooledByteBufferWriter?>(ref _extraPooledByteBufferWriter, null);
extraBufferWriter?.Dispose();
Expand DownExpand Up@@ -326,7 +326,7 @@ internal unsafe bool TextEquals(int index, ReadOnlySpan<char> otherText, bool is
result = TextEquals(index, otherUtf8Text.Slice(0, written), isPropertyName, shouldUnescape: true);
}

if (otherUtf8TextArray != null)
if (otherUtf8TextArray is not null)
{
otherUtf8Text.Slice(0, written).Clear();
ArrayPool<byte>.Shared.Return(otherUtf8TextArray);
Expand DownExpand Up@@ -832,7 +832,7 @@ private ReadOnlySpan<byte> UnescapeString(in DbRow row, out ArraySegment<byte> r

private static void ClearAndReturn(ArraySegment<byte> rented)
{
if (rented.Array != null)
if (rented.Array is not null)
{
rented.AsSpan().Clear();
ArrayPool<byte>.Shared.Return(rented.Array);
Expand DownExpand Up@@ -998,7 +998,7 @@ private static void Parse(
}
else
{
Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
Debug.Assert(tokenType is >= JsonTokenType.String and <= JsonTokenType.Null);
numberOfRowsForValues++;
numberOfRowsForMembers++;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ public static JsonElement ParseValue(ref Utf8JsonReader reader)
bool ret = JsonDocument.TryParseValue(ref reader, out JsonDocument? document, shouldThrow: true, useArrayPools: false);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand All@@ -63,7 +63,7 @@ internal static JsonElement ParseValue(ref Utf8JsonReader reader, bool allowDupl
allowDuplicateProperties: allowDuplicateProperties);

Debug.Assert(ret, "TryParseValue returned false with shouldThrow: true.");
Debug.Assert(document != null, "null document returned with shouldThrow: true.");
Debug.Assert(document is not null, "null document returned with shouldThrow: true.");
return document.RootElement;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1442,7 +1442,7 @@ public bool ValueEquals(string? text)

if (TokenType == JsonTokenType.Null)
{
return text == null;
return text is null;
}

return TextEqualsHelper(text.AsSpan(), isPropertyName: false);
Expand DownExpand Up@@ -1661,7 +1661,7 @@ public override string ToString()
case JsonTokenType.StartObject:
{
// null parent should have hit the None case
Debug.Assert(_parent != null);
Debug.Assert(_parent is not null);
return _parent.GetRawValueAsString(_idx);
}
case JsonTokenType.String:
Expand DownExpand Up@@ -1704,7 +1704,7 @@ public JsonElement Clone()

private void CheckValidInstance()
{
if (_parent == null)
if (_parent is null)
{
throw new InvalidOperationException();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ namespace System.Text.Json

private JsonEncodedText(byte[] utf8Value)
{
Debug.Assert(utf8Value != null);
Debug.Assert(utf8Value is not null);

_value = JsonReaderHelper.GetTextFromUtf8(utf8Value);
_utf8Value = utf8Value;
Expand DownExpand Up@@ -143,9 +143,9 @@ private static JsonEncodedText EncodeHelper(ReadOnlySpan<byte> utf8Value, JavaSc
/// </remarks>
public bool Equals(JsonEncodedText other)
{
if (_value == null)
if (_value is null)
{
return other._value == null;
return other._value is null;
}
else
{
Expand DownExpand Up@@ -187,6 +187,6 @@ public override string ToString()
/// Returns 0 on a default instance of <see cref="JsonEncodedText"/>.
/// </remarks>
public override int GetHashCode()
=> _value == null ? 0 : _value.GetHashCode();
=> _value?.GetHashCode() ?? 0;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ public static unsafe byte[] EscapeValue(

byte[] escapedString = escapedValue.Slice(0, written).ToArray();

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand DownExpand Up@@ -73,7 +73,7 @@ private static unsafe byte[] GetEscapedPropertyNameSection(

byte[] propertySection = GetPropertyNameSection(escapedValue.Slice(0, written));

if (valueArray != null)
if (valueArray is not null)
{
ArrayPool<byte>.Shared.Return(valueArray);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ public static unsafe bool TryLookupUtf8Key<TValue>(

bool success = spanLookup.TryGetValue(decodedKey, out result);

if (rentedBuffer != null)
if (rentedBuffer is not null)
{
decodedKey.Clear();
ArrayPool<char>.Shared.Return(rentedBuffer);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,7 +242,7 @@ internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? chi
{
Parent?.GetPath(ref path, this);

if (child != null)
if (child is not null)
{
int index = List.IndexOf(child);
Debug.Assert(index >= 0);
Expand DownExpand Up@@ -380,7 +380,7 @@ public string Display
{
get
{
if (Value == null)
if (Value is null)
{
return $"null";
}
Expand Down
Loading