Skip to content

Commit 3110620

Browse files
authored
Merge pull request #1038 from dotnet/dev/bartde/more_null_warnings
Fix a few more nullability warnings
2 parents c42762e + 2db68a9 commit 3110620

File tree

15 files changed

+58
-46
lines changed

15 files changed

+58
-46
lines changed

Ix.NET/Source/Benchmarks.System.Interactive/BufferCountBenchmark.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Linq;
87
using System.Threading;
@@ -15,7 +14,7 @@ public class BufferCountBenchmark
1514
{
1615
[Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
1716
public int N;
18-
private IList<int> _store;
17+
private IList<int>? _store;
1918

2019
[Benchmark]
2120
public void Exact()

Ix.NET/Source/Benchmarks.System.Interactive/IgnoreElementsBenchmark.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Linq;
87
using System.Threading;
@@ -18,8 +17,8 @@ public class IgnoreElementsBenchmark
1817

1918
private int _store;
2019

21-
private int[] _array;
22-
private List<int> _list;
20+
private int[]? _array;
21+
private List<int>? _list;
2322

2423
[Benchmark]
2524
public void Ignore()
@@ -32,15 +31,15 @@ public void Ignore()
3231
[Benchmark]
3332
public void IgnoreList()
3433
{
35-
_list
34+
_list!
3635
.IgnoreElements()
3736
.Subscribe(v => Volatile.Write(ref _store, v));
3837
}
3938

4039
[Benchmark]
4140
public void IgnoreArray()
4241
{
43-
_array
42+
_array!
4443
.IgnoreElements()
4544
.Subscribe(v => Volatile.Write(ref _store, v));
4645
}

Ix.NET/Source/Benchmarks.System.Interactive/MinMaxBenchmark.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Linq;
87
using System.Threading;
@@ -16,7 +15,7 @@ public class MinMaxBenchmark
1615
[Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
1716
public int N;
1817
private int _store;
19-
private IList<int> _listStore;
18+
private IList<int>? _listStore;
2019

2120
private readonly IComparer<int> _comparer = Comparer<int>.Default;
2221

Ix.NET/Source/System.Interactive.Providers/System/Linq/QueryableEx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static ILookup<string, MethodInfo> GetMethods(Type type)
100100
return type.GetMethods(BindingFlags.Static | BindingFlags.Public).ToLookup(m => m.Name);
101101
}
102102

103-
private static bool ArgsMatch(MethodInfo method, IList<Expression> arguments, Type[] typeArgs)
103+
private static bool ArgsMatch(MethodInfo method, IList<Expression> arguments, Type[]? typeArgs)
104104
{
105105
//
106106
// Number of parameters should match. Notice we've sanitized IQueryProvider "this"

Ix.NET/Source/System.Interactive/System/Linq/Operators/DistinctUntilChanged.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static IEnumerable<TSource> DistinctUntilChanged<TSource, TKey>(this IEnu
8080

8181
private static IEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
8282
{
83-
var currentKey = default(TKey);
83+
var currentKey = default(TKey)!;
8484
var hasCurrentKey = false;
8585

8686
foreach (var item in source)

Ix.NET/Source/System.Interactive/System/Linq/Operators/Memoize.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ public static IEnumerable<TResult> Memoize<TSource, TResult>(this IEnumerable<TS
113113

114114
private sealed class MemoizedBuffer<T> : IBuffer<T>
115115
{
116-
private IRefCountList<T> _buffer;
116+
private readonly object _gate = new object();
117+
private readonly IRefCountList<T> _buffer;
118+
private readonly IEnumerator<T> _source;
119+
117120
private bool _disposed;
118121
private Exception? _error;
119-
private IEnumerator<T> _source;
120122
private bool _stopped;
121123

122124
public MemoizedBuffer(IEnumerator<T> source)
@@ -153,15 +155,12 @@ IEnumerator IEnumerable.GetEnumerator()
153155

154156
public void Dispose()
155157
{
156-
lock (_source)
158+
lock (_gate)
157159
{
158160
if (!_disposed)
159161
{
160162
_source.Dispose();
161-
_source = null;
162-
163163
_buffer.Clear();
164-
_buffer = null;
165164
}
166165

167166
_disposed = true;
@@ -180,9 +179,9 @@ private IEnumerator<T> GetEnumerator_()
180179
throw new ObjectDisposedException("");
181180

182181
var hasValue = default(bool);
183-
var current = default(T);
182+
var current = default(T)!;
184183

185-
lock (_source)
184+
lock (_gate)
186185
{
187186
if (i >= _buffer.Count)
188187
{

Ix.NET/Source/System.Interactive/System/Linq/Operators/OnErrorResumeNext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static IEnumerable<TSource> OnErrorResumeNextCore<TSource>(IEnumerable<I
6363

6464
while (true)
6565
{
66-
var value = default(TSource);
66+
TSource value;
6767
try
6868
{
6969
if (!innerEnumerator.MoveNext())

Ix.NET/Source/System.Interactive/System/Linq/Operators/Publish.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public static IEnumerable<TResult> Publish<TSource, TResult>(this IEnumerable<TS
6262
private sealed class PublishedBuffer<T> : IBuffer<T>
6363
{
6464
private readonly object _gate = new object();
65+
private readonly RefCountList<T> _buffer;
66+
private readonly IEnumerator<T> _source;
6567

66-
private RefCountList<T> _buffer;
6768
private bool _disposed;
6869
private Exception? _error;
69-
private IEnumerator<T> _source;
7070
private bool _stopped;
7171

7272
public PublishedBuffer(IEnumerator<T> source)
@@ -109,10 +109,7 @@ public void Dispose()
109109
if (!_disposed)
110110
{
111111
_source.Dispose();
112-
_source = null;
113-
114112
_buffer.Clear();
115-
_buffer = null;
116113
}
117114

118115
_disposed = true;
@@ -131,7 +128,7 @@ private IEnumerator<T> GetEnumeratorCore(int i)
131128
}
132129

133130
var hasValue = default(bool);
134-
var current = default(T);
131+
var current = default(T)!;
135132

136133
lock (_gate)
137134
{

Ix.NET/Source/System.Interactive/System/Linq/Operators/Scan.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static IEnumerable<TAccumulate> ScanCore<TSource, TAccumulate>(IEnumerab
6565
private static IEnumerable<TSource> ScanCore<TSource>(IEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator)
6666
{
6767
var hasSeed = false;
68-
var acc = default(TSource);
68+
var acc = default(TSource)!;
6969

7070
foreach (var item in source)
7171
{

Ix.NET/Source/System.Interactive/System/Linq/Operators/Share.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public static IEnumerable<TResult> Share<TSource, TResult>(this IEnumerable<TSou
5858

5959
private class SharedBuffer<T> : IBuffer<T>
6060
{
61+
private readonly IEnumerator<T> _source;
6162
private bool _disposed;
62-
private IEnumerator<T> _source;
6363

6464
public SharedBuffer(IEnumerator<T> source)
6565
{
@@ -89,7 +89,6 @@ public void Dispose()
8989
if (!_disposed)
9090
{
9191
_source.Dispose();
92-
_source = null;
9392
}
9493

9594
_disposed = true;
@@ -104,11 +103,15 @@ private sealed class ShareEnumerator : IEnumerator<T>
104103

105104
private bool _disposed;
106105

107-
public ShareEnumerator(SharedBuffer<T> parent) => _parent = parent;
106+
public ShareEnumerator(SharedBuffer<T> parent)
107+
{
108+
_parent = parent;
109+
Current = default!;
110+
}
108111

109112
public T Current { get; private set; }
110113

111-
object IEnumerator.Current => Current;
114+
object? IEnumerator.Current => Current;
112115

113116
public void Dispose() => _disposed = true;
114117

@@ -138,7 +141,7 @@ public bool MoveNext()
138141
return true;
139142
}
140143
_disposed = true;
141-
Current = default;
144+
Current = default!;
142145
return false;
143146
}
144147

0 commit comments

Comments
 (0)