Skip to content

inline some out variables #6712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2023
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
3 changes: 1 addition & 2 deletions src/benchmark/PingPong/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public static uint CpuSpeed()

private static void Main(params string[] args)
{
uint timesToRun;
if (args.Length == 0 || !uint.TryParse(args[0], out timesToRun))
if (args.Length == 0 || !uint.TryParse(args[0], out var timesToRun))
{
timesToRun = 1u;
}
Expand Down
3 changes: 1 addition & 2 deletions src/benchmark/RemotePingPong/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public static Config CreateActorSystemConfig(string actorSystemName, string ipOr
private static async Task Main(params string[] args)
{
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
uint timesToRun;
if (args.Length == 0 || !uint.TryParse(args[0], out timesToRun))
if (args.Length == 0 || !uint.TryParse(args[0], out var timesToRun))
{
timesToRun = 1u;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ public DistributedPubSubMediator(DistributedPubSubSettings settings)
Receive<Send>(send =>
{
var routees = new List<Routee>();
ValueHolder valueHolder;
if (_registry.TryGetValue(_cluster.SelfAddress, out var bucket) &&
bucket.Content.TryGetValue(send.Path, out valueHolder) &&
bucket.Content.TryGetValue(send.Path, out var valueHolder) &&
send.LocalAffinity)
{
var routee = valueHolder.Routee;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ private void SendFirstChange()
// don't send cluster change events if this node is shutting its self down, just wait for SelfExiting
if (!_cluster.IsTerminated)
{
object change;
_changes = _changes.Dequeue(out change);
_changes = _changes.Dequeue(out var change);
Context.Parent.Tell(change);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ public void ORDictionary_must_do_not_have_divergence_in_dot_versions_between_the
var delta = m1.Delta as ORDictionary<string, GSet<string>>.PutDeltaOperation;
if (delta != null)
{
VersionVector v;
var addDelta = delta.Underlying as ORSet<string>.AddDeltaOperation;
if (addDelta != null && addDelta.Underlying.ElementsMap.TryGetValue("a", out v))
if (addDelta != null && addDelta.Underlying.ElementsMap.TryGetValue("a", out var v))
deltaVersion = v.VersionAt(_node1);
}

VersionVector v2;
var fullVersion = !m1.KeySet.ElementsMap.TryGetValue("a", out v2)
var fullVersion = !m1.KeySet.ElementsMap.TryGetValue("a", out var v2)
? default(long?)
: v2.VersionAt(_node1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ public void ORMultiDictionary_must_be_able_to_get_all_bindings_for_an_entry_and_
.AddItem(_node1, "a", "A2")
.AddItem(_node1, "b", "B1");

IImmutableSet<string> a;
m.TryGetValue("a", out a);
m.TryGetValue("a", out var a);
Assert.Equal(ImmutableHashSet.Create("A1", "A2"), a);

var m2 = m.SetItems(_node1, "a", a.Remove("A1"));
Expand All @@ -200,8 +199,7 @@ public void ORMultiDictionary_must_return_the_value_for_an_existing_key_and_the_
var m = ORMultiValueDictionary<string, string>.Empty
.AddItem(_node1, "a", "A");

IImmutableSet<string> v;
m.TryGetValue("a", out v).Should().BeTrue();
m.TryGetValue("a", out var v).Should().BeTrue();
v.Should().BeEquivalentTo("A");

m.TryGetValue("b", out v).Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public ImmutableDictionary<Address, DeltaPropagation> CollectPropagations()

public bool HasDeltaEntries(string key)
{
ImmutableSortedDictionary<long, IReplicatedData> entries;
if (_deltaEntries.TryGetValue(key, out entries))
if (_deltaEntries.TryGetValue(key, out var entries))
{
return !entries.IsEmpty;
}
Expand Down
6 changes: 2 additions & 4 deletions src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ public LWWDictionary<TKey, TValue> SetItem(Cluster.Cluster node, TKey key, TValu
public LWWDictionary<TKey, TValue> SetItem(UniqueAddress node, TKey key, TValue value,
Clock<TValue> clock = null)
{
LWWRegister<TValue> register;
var newRegister = Underlying.TryGetValue(key, out register)
var newRegister = Underlying.TryGetValue(key, out var register)
? register.WithValue(node, value, clock ?? LWWRegister<TValue>.DefaultClock)
: new LWWRegister<TValue>(node, value, clock ?? LWWRegister<TValue>.DefaultClock);

Expand Down Expand Up @@ -244,8 +243,7 @@ public LWWDictionary<TKey, TValue> Remove(UniqueAddress node, TKey key) =>
/// <returns>TBD</returns>
public bool TryGetValue(TKey key, out TValue value)
{
LWWRegister<TValue> register;
if (Underlying.TryGetValue(key, out register))
if (Underlying.TryGetValue(key, out var register))
{
value = register.Value;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public bool TryGetValue(TKey key, out IImmutableSet<TValue> value)
{
if (!_withValueDeltas || Underlying.KeySet.Contains(key))
{
ORSet<TValue> set;
if (Underlying.TryGetValue(key, out set))
if (Underlying.TryGetValue(key, out var set))
{
value = set.Elements;
return true;
Expand Down Expand Up @@ -224,8 +223,7 @@ public ORMultiValueDictionary<TKey, TValue> RemoveItem(Cluster.Cluster node, TKe
public ORMultiValueDictionary<TKey, TValue> RemoveItem(UniqueAddress node, TKey key, TValue element)
{
var newUnderlying = Underlying.AddOrUpdate(node, key, ORSet<TValue>.Empty, _withValueDeltas, set => set.Remove(node, element));
ORSet<TValue> found;
if (newUnderlying.TryGetValue(key, out found) && found.IsEmpty)
if (newUnderlying.TryGetValue(key, out var found) && found.IsEmpty)
{
if (_withValueDeltas)
newUnderlying = newUnderlying.RemoveKey(node, key);
Expand Down
3 changes: 1 addition & 2 deletions src/contrib/cluster/Akka.DistributedData/ORSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ internal static ImmutableDictionary<T, VersionVector> MergeCommonKeys(IEnumerabl
var commonDots = rhsDots.Versions
.Where(kv =>
{
long v;
return rhsDots.Versions.TryGetValue(kv.Key, out v) && v == kv.Value;
return rhsDots.Versions.TryGetValue(kv.Key, out var v) && v == kv.Value;
}).ToImmutableDictionary();
var commonDotKeys = commonDots.Keys.ToImmutableArray();
var lhsUniqueDots = lhsDots.Versions.RemoveRange(commonDotKeys);
Expand Down
12 changes: 4 additions & 8 deletions src/contrib/cluster/Akka.DistributedData/Replicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,7 @@ private void ReceiveGossip(IImmutableDictionary<string, DataEnvelope> updatedDat

private void ReceiveSubscribe(IKey key, IActorRef subscriber)
{
HashSet<IActorRef> set;
if (!_newSubscribers.TryGetValue(key.Id, out set))
if (!_newSubscribers.TryGetValue(key.Id, out var set))
{
_newSubscribers[key.Id] = set = new HashSet<IActorRef>();
}
Expand All @@ -1233,8 +1232,7 @@ private void ReceiveSubscribe(IKey key, IActorRef subscriber)

private void ReceiveUnsubscribe(IKey key, IActorRef subscriber)
{
HashSet<IActorRef> set;
if (_subscribers.TryGetValue(key.Id, out set) && set.Remove(subscriber) && set.Count == 0)
if (_subscribers.TryGetValue(key.Id, out var set) && set.Remove(subscriber) && set.Count == 0)
_subscribers.Remove(key.Id);

if (_newSubscribers.TryGetValue(key.Id, out set) && set.Remove(subscriber) && set.Count == 0)
Expand Down Expand Up @@ -1268,8 +1266,7 @@ private void ReceiveTerminated(IActorRef terminated)

foreach (var k in keys1)
{
HashSet<IActorRef> set;
if (_subscribers.TryGetValue(k, out set) && set.Remove(terminated) && set.Count == 0)
if (_subscribers.TryGetValue(k, out var set) && set.Remove(terminated) && set.Count == 0)
_subscribers.Remove(k);
}

Expand All @@ -1279,8 +1276,7 @@ private void ReceiveTerminated(IActorRef terminated)

foreach (var k in keys2)
{
HashSet<IActorRef> set;
if (_newSubscribers.TryGetValue(k, out set) && set.Remove(terminated) && set.Count == 0)
if (_newSubscribers.TryGetValue(k, out var set) && set.Remove(terminated) && set.Count == 0)
_newSubscribers.Remove(k);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public static SqliteConnection Remember(string connectionString)
/// <param name="connectionString">TBD</param>
public static void Forget(string connectionString)
{
SqliteConnection conn;
if (Remembered.TryRemove(connectionString, out conn))
if (Remembered.TryRemove(connectionString, out var conn))
{
conn.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,7 @@ private void WeMustGoDeeper(string dWithDepth)
{
var d = dWithDepth.Split('-')[0];
_probe.Tell(dWithDepth);
int currentDepth;
if (!_currentDepths.TryGetValue(d, out currentDepth)) currentDepth = 1;
if (!_currentDepths.TryGetValue(d, out var currentDepth)) currentDepth = 1;
if (currentDepth < _maxDepth)
{
_currentDepths[d] = currentDepth + 1;
Expand Down Expand Up @@ -1264,8 +1263,7 @@ private void WeMustGoDeeper(string dWithDepth)
{
var d = dWithDepth.Split('-')[0];
_probe.Tell(dWithDepth);
int currentDepth;
if (!_currentDepths.TryGetValue(d, out currentDepth)) currentDepth = 1;
if (!_currentDepths.TryGetValue(d, out var currentDepth)) currentDepth = 1;
if (currentDepth < _maxDepth)
{
_currentDepths[d] = currentDepth + 1;
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Persistence/Snapshot/LocalSnapshotStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ private SnapshotMetadata ExtractSnapshotMetadata(FileInfo fileInfo)
var seqNrString = match.Groups[2].Value;
var timestampTicks = match.Groups[3].Value;

long sequenceNr, ticks;
if (long.TryParse(seqNrString, out sequenceNr) && long.TryParse(timestampTicks, out ticks))
if (long.TryParse(seqNrString, out var sequenceNr) && long.TryParse(timestampTicks, out var ticks))
{
return new SnapshotMetadata(pid, sequenceNr, new DateTime(ticks));
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Remote/RemoteDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public override Deploy ParseConfig(string key, Config config)

var remote = deploy.Config.GetString("remote", null);

ActorPath actorPath;
if(ActorPath.TryParse(remote, out actorPath))
if(ActorPath.TryParse(remote, out var actorPath))
{
var address = actorPath.Address;
//can have remotely deployed routers that remotely deploy routees
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Remote/RemoteSystemDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ private void HandleDaemonMsgCreate(DaemonMsgCreate message)
var supervisor = (IInternalActorRef) message.Supervisor;
var parent = supervisor;
Props props = message.Props;
ActorPath childPath;
if(ActorPath.TryParse(message.Path, out childPath))
if(ActorPath.TryParse(message.Path, out var childPath))
{
IEnumerable<string> subPath = childPath.ElementsWithUid.Drop(1); //drop the /remote
ActorPath p = Path/subPath;
Expand Down
4 changes: 1 addition & 3 deletions src/core/Akka.Remote/Serialization/ActorPathCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public ActorPathCache(int capacity = 1024, int evictAgeThreshold = 600)

protected override ActorPath Compute(string k)
{
ActorPath actorPath;

var path = k.AsSpan();

if (!ActorPath.TryParseParts(path, out var addressSpan, out var absoluteUri))
Expand All @@ -70,7 +68,7 @@ protected override ActorPath Compute(string k)
}

//try lookup root in cache
if (!TryGet(rootPath, out actorPath))
if (!TryGet(rootPath, out var actorPath))
{
if (!Address.TryParse(addressSpan, out var address))
return null;
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Remote/Serialization/AddressCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public AddressCache(int capacity = 1024, int evictAgeThreshold = 600)

protected override Address Compute(string k)
{
Address addr;
if (ActorPath.TryParseAddress(k, out addr))
if (ActorPath.TryParseAddress(k, out var addr))
{
return addr;
}
Expand Down
12 changes: 4 additions & 8 deletions src/core/Akka.Remote/Transport/DotNetty/DotNettyTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ protected async Task<IChannel> NewServer(EndPoint listenAddress)
public override async Task<(Address, TaskCompletionSource<IAssociationEventListener>)> Listen()
{
EndPoint listenAddress;
IPAddress ip;
if (IPAddress.TryParse(Settings.Hostname, out ip))
if (IPAddress.TryParse(Settings.Hostname, out var ip))
listenAddress = new IPEndPoint(ip, Settings.Port);
else
listenAddress = new DnsEndPoint(Settings.Hostname, Settings.Port);
Expand Down Expand Up @@ -439,8 +438,7 @@ public static Address MapSocketToAddress(IPEndPoint socketAddress, string scheme

private static string SafeMapHostName(string hostName)
{
IPAddress ip;
return !string.IsNullOrEmpty(hostName) && IPAddress.TryParse(hostName, out ip) ? SafeMapIPv6(ip) : hostName;
return !string.IsNullOrEmpty(hostName) && IPAddress.TryParse(hostName, out var ip) ? SafeMapIPv6(ip) : hostName;
}

private static string SafeMapIPv6(IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetworkV6 ? "[" + ip + "]" : ip.ToString();
Expand All @@ -449,8 +447,7 @@ public static EndPoint ToEndpoint(Address address)
{
if (!address.Port.HasValue) throw new ArgumentNullException(nameof(address), $"Address port must not be null: {address}");

IPAddress ip;
return IPAddress.TryParse(address.Host, out ip)
return IPAddress.TryParse(address.Host, out var ip)
? (EndPoint)new IPEndPoint(ip, address.Port.Value)
: new DnsEndPoint(address.Host, address.Port.Value);
}
Expand All @@ -465,8 +462,7 @@ public static EndPoint AddressToSocketAddress(Address address)
{
if (address.Port == null) throw new ArgumentException($"address port must not be null: {address}");
EndPoint listenAddress;
IPAddress ip;
if (IPAddress.TryParse(address.Host, out ip))
if (IPAddress.TryParse(address.Host, out var ip))
{
listenAddress = new IPEndPoint(ip, (int)address.Port);
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Remote/Transport/TestTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,7 @@ public Func<TIn, Task<TOut>> CurrentBehavior
{
get
{
Func<TIn, Task<TOut>> behavior;
if (_behaviorStack.TryPeek(out behavior))
if (_behaviorStack.TryPeek(out var behavior))
return behavior;
return DefaultBehavior; //otherwise, return the default behavior
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Streams/Actors/ActorPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,7 @@ public State Get(IActorRef actorRef)
/// <returns>TBD</returns>
public State Remove(IActorRef actorRef)
{
State s;
return _state.TryRemove(actorRef, out s) ? s : null;
return _state.TryRemove(actorRef, out var s) ? s : null;
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Streams/Actors/ActorSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ public State Get(IActorRef actorRef)
/// <returns>TBD</returns>
public State Remove(IActorRef actorRef)
{
State s;
return _state.TryRemove(actorRef, out s) ? s : null;
return _state.TryRemove(actorRef, out var s) ? s : null;
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Streams/Dsl/Tcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ public TcpExt(ExtendedActorSystem system)

internal static EndPoint CreateEndpoint(string host, int port)
{
IPAddress address;
return IPAddress.TryParse(host, out address)
return IPAddress.TryParse(host, out var address)
? (EndPoint) new IPEndPoint(address, port)
: new DnsEndPoint(host, port);
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Streams/Implementation/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ protected SourceModule(SourceShape<TOut> shape)

IUntypedPublisher ISourceModule.Create(MaterializationContext context, out object materializer)
{
TMat m;
var result = Create(context, out m);
var result = Create(context, out var m);
materializer = m;
return UntypedPublisher.FromTyped(result);
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Streams/Implementation/Sinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ protected SinkModule(SinkShape<TIn> shape)

object ISinkModule.Create(MaterializationContext context, out object materializer)
{
TMat m;
var result = Create(context, out m);
var result = Create(context, out var m);
materializer = m;
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public bool IsMatch(string path)
if (String.Equals(_path, path, StringComparison.OrdinalIgnoreCase)) return true;
if(!_canBeRelative)return false;

ActorPath actorPath;
if (!ActorPath.TryParse(path, out actorPath)) return false;
if (!ActorPath.TryParse(path, out var actorPath)) return false;
var pathWithoutAddress = actorPath.ToStringWithoutAddress();
return String.Equals(_path, pathWithoutAddress, StringComparison.OrdinalIgnoreCase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public List<T> ToList()
/// <returns>An enumeration of all items removed from the queue.</returns>
public IEnumerable<T> GetAll()
{
T item;
while(_queue.TryTake(out item))
while(_queue.TryTake(out var item))
{
yield return item;
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.TestKit/TestScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public void Advance(TimeSpan offset)
si.DeliveryCount++;
}

ConcurrentQueue<ScheduledItem> removed;
_scheduledWork.TryRemove(t.Key, out removed);
_scheduledWork.TryRemove(t.Key, out var removed);

foreach (var i in removed.Where(r => r.Repeating && (r.Cancelable == null || !r.Cancelable.IsCancellationRequested)))
{
Expand Down
Loading