Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasoukhov committed Nov 7, 2024
1 parent 7281c20 commit 565e7e7
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Collections/CachedSynchronizedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public TKey[] CachedKeys
get
{
lock (SyncRoot)
return _cachedKeys ??= Keys.ToArray();
return _cachedKeys ??= [.. Keys];
}
}

Expand All @@ -42,7 +42,7 @@ public TValue[] CachedValues
get
{
lock (SyncRoot)
return _cachedValues ??= Values.ToArray();
return _cachedValues ??= [.. Values];
}
}

Expand All @@ -53,7 +53,7 @@ public KeyValuePair<TKey, TValue>[] CachedPairs
get
{
lock (SyncRoot)
return _cachedPairs ??= this.ToArray();
return _cachedPairs ??= [.. this];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Collections/CachedSynchronizedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public T[] Cache
get
{
lock (SyncRoot)
return _cache ??= this.ToArray();
return _cache ??= [.. this];
}
}

Expand Down
6 changes: 3 additions & 3 deletions Collections/CachedSynchronizedOrderedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TKey[] CachedKeys
get
{
lock (SyncRoot)
return _cachedKeys ??= Keys.ToArray();
return _cachedKeys ??= [.. Keys];
}
}

Expand All @@ -38,7 +38,7 @@ public TValue[] CachedValues
get
{
lock (SyncRoot)
return _cachedValues ??= Values.ToArray();
return _cachedValues ??= [.. Values];
}
}

Expand All @@ -49,7 +49,7 @@ public KeyValuePair<TKey, TValue>[] CachedPairs
get
{
lock (SyncRoot)
return _cachedPairs ??= this.ToArray();
return _cachedPairs ??= [.. this];
}
}

Expand Down
6 changes: 3 additions & 3 deletions Collections/CachedSynchronizedPairSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TKey[] CachedKeys
get
{
lock (SyncRoot)
return _cachedKeys ??= Keys.ToArray();
return _cachedKeys ??= [.. Keys];
}
}

Expand All @@ -37,7 +37,7 @@ public TValue[] CachedValues
get
{
lock (SyncRoot)
return _cachedValues ??= Values.ToArray();
return _cachedValues ??= [.. Values];
}
}

Expand All @@ -48,7 +48,7 @@ public KeyValuePair<TKey, TValue>[] CachedPairs
get
{
lock (SyncRoot)
return _cachedPairs ??= this.ToArray();
return _cachedPairs ??= [.. this];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Collections/CachedSynchronizedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public T[] Cache
get
{
lock (SyncRoot)
return _cache ??= this.ToArray();
return _cache ??= [.. this];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Collections/CollectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ public static bool[] ToBits(this long value, int startBit, int bitCount)
if ((startBit + bitCount) > 32)
bits.AddRange(ints[1].ToBits((startBit - 32).Max(0), (bitCount - 32)));

return bits.ToArray();
return [.. bits];
}

public static bool[] ToBits(this int value)
Expand Down
2 changes: 1 addition & 1 deletion Collections/OrderedPriorityQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void RemoveRange(IEnumerable<KeyValuePair<TPriority, TValue>> items)

foreach (var g in groups)
{
Remove(g.Key, g.ToList());
Remove(g.Key, [.. g]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Common/FastCsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FastCsvReader(TextReader reader, string lineSeparator)
throw new ArgumentNullException(nameof(lineSeparator));

Reader = reader ?? throw new ArgumentNullException(nameof(reader));
_lineSeparatorChars = lineSeparator.ToArray();
_lineSeparatorChars = [.. lineSeparator];

for (var i = 0; i < _columnPos.Length; i++)
_columnPos[i] = new RefPair<int, int>();
Expand Down
2 changes: 1 addition & 1 deletion Common/FastDateTimeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public FastDateTimeParser(string template)
};
}

_parts = parts2.ToArray();
_parts = [.. parts2];

//TimeHelper.InitBounds(template, 'y', out _yearStart, out _yearLen);
//TimeHelper.InitBounds(template, 'M', out _monthStart, out _monthLen);
Expand Down
2 changes: 1 addition & 1 deletion Common/FastTimeSpanParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public FastTimeSpanParser(string template)
};
}

_parts = parts2.ToArray();
_parts = [.. parts2];

//TimeHelper.InitBounds(template, 'd', out _dayStart, out _dayLen);
//TimeHelper.InitBounds(template, 'h', out _hourStart, out _hourLen);
Expand Down
2 changes: 1 addition & 1 deletion Common/TimeZoneConverter/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void Populate(IDictionary<string, string> ianaMap, IDictionary<str

foreach (var grouping in railsMap.GroupBy(x => x.Value, x => x.Key))
{
inverseRailsMap.Add(grouping.Key, grouping.ToList());
inverseRailsMap.Add(grouping.Key, [.. grouping]);
}

// Expand the Inverse Rails map to include similar IANA zones
Expand Down
2 changes: 1 addition & 1 deletion Common/TupleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static object ToTuple(this IEnumerable<object> values, bool isValue)
var genericType = $"System.{prefix}Tuple`{types.Count}".To<Type>();
var specificType = genericType.Make(types);

return specificType.CreateInstance(args.ToArray());
return specificType.CreateInstance([.. args]);
}

public static IEnumerable<object> ToValues<T>(this T tuple)
Expand Down
2 changes: 1 addition & 1 deletion ComponentModel/DispatcherObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private void OnFlush()
lock (SyncRoot)
{
_isTimerStarted = false;
actions = _pendingActions.ToArray();
actions = [.. _pendingActions];
_pendingActions.Clear();
}

Expand Down
2 changes: 1 addition & 1 deletion IO/FossilDelta/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public unsafe void PutArray (byte* a, int start, int end) {

public byte[] ToArray ()
{
return this.a.ToArray();
return [.. this.a];
}

}
Expand Down
2 changes: 1 addition & 1 deletion Linq/AsyncEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static async ValueTask<T[]> ToArrayAsync2<T>(this IAsyncEnumerable<T> enu
await foreach (var item in enu.WithEnforcedCancellation(cancellationToken))
list.Add(item);

return list.ToArray();
return [.. list];
}

public static async ValueTask<T> FirstAsync2<T>(this IAsyncEnumerable<T> enu, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion Net/NetworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static string ClearUrl(this string url)
}
}

return new string(chars.ToArray());
return new string([.. chars]);
}

public static bool IsUrlSafeChar(this char ch)
Expand Down
4 changes: 2 additions & 2 deletions Nuget/NugetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static string[] GetTargetFrameworks(this PackageArchiveReader reader)
targetFrameworks.Add("any");
}

return targetFrameworks.ToArray();
return [.. targetFrameworks];
}

public static NuGetFramework RemovePlatformVersion(this NuGetFramework fwk)
Expand All @@ -45,7 +45,7 @@ public static async Task<NuGetVersion[]> GetAllVersionsOrderedAsync(this SourceR
{
var resource = await repo.GetResourceAsync<FindPackageByIdResource>(token);

return (await resource.GetAllVersionsAsync(packageId, cache, logger, token)).OrderBy(v => v).ToArray();
return [.. (await resource.GetAllVersionsAsync(packageId, cache, logger, token)).OrderBy(v => v)];
}

public static async Task<NuGetVersion> GetLastVersionAsync(this SourceRepository repo, string packageId, bool allowPreview, ILogger logger, SourceCacheContext cache, CancellationToken token)
Expand Down
2 changes: 1 addition & 1 deletion SmartFormat/SmartFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public string[] GetNotEmptyFormatterExtensionNames()
var names = new List<string>();
foreach (var extension in FormatterExtensions)
names.AddRange(extension.Names.Where(n => n != string.Empty).ToArray());
return names.ToArray();
return [.. names];
}

/// <summary>
Expand Down

0 comments on commit 565e7e7

Please sign in to comment.