Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Commit 7757f45

Browse files
authored
Merge pull request #426 from marco-carvalho/performance
Preventing duplicate casts and optimize collection checks
2 parents ec7907c + e10c472 commit 7757f45

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

Optimizer/DebugHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static void FindDifferenceInTwoJsons()
1818
var p1 = file1.Properties().ToList();
1919
var p2 = file2.Properties().ToList();
2020

21-
var missingProps = p1.Where(expected => p2.Where(actual => actual.Name == expected.Name).Count() == 0);
21+
var missingProps = p1.Where(expected => !p2.Where(actual => actual.Name == expected.Name).Any());
2222

2323
StringBuilder sb = new StringBuilder();
2424
foreach (var x in missingProps)

Optimizer/Forms/MainForm.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,42 +1192,42 @@ private void LoadNetworkAdapterConfig()
11921192
if (_currentDNS == null) return;
11931193
if (_currentDNS.Length == 0) return;
11941194

1195-
if (PingerHelper.CloudflareDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1195+
if (Array.Exists(PingerHelper.CloudflareDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
11961196
{
11971197
boxDNS.Text = Constants.CloudflareDNS;
11981198
return;
11991199
}
1200-
else if (PingerHelper.OpenDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1200+
else if (Array.Exists(PingerHelper.OpenDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12011201
{
12021202
boxDNS.Text = Constants.OpenDNS;
12031203
return;
12041204
}
1205-
else if (PingerHelper.Quad9DNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1205+
else if (Array.Exists(PingerHelper.Quad9DNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12061206
{
12071207
boxDNS.Text = Constants.Quad9DNS;
12081208
return;
12091209
}
1210-
else if (PingerHelper.GoogleDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1210+
else if (Array.Exists(PingerHelper.GoogleDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12111211
{
12121212
boxDNS.Text = Constants.GoogleDNS;
12131213
return;
12141214
}
1215-
else if (PingerHelper.AlternateDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1215+
else if (Array.Exists(PingerHelper.AlternateDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12161216
{
12171217
boxDNS.Text = Constants.AlternateDNS;
12181218
return;
12191219
}
1220-
else if (PingerHelper.AdguardDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1220+
else if (Array.Exists(PingerHelper.AdguardDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12211221
{
12221222
boxDNS.Text = Constants.AdguardDNS;
12231223
return;
12241224
}
1225-
else if (PingerHelper.CleanBrowsingDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1225+
else if (Array.Exists(PingerHelper.CleanBrowsingDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12261226
{
12271227
boxDNS.Text = Constants.CleanBrowsingDNS;
12281228
return;
12291229
}
1230-
else if (PingerHelper.CleanBrowsingAdultDNSv4.Any(x => _currentDNS.Select(y => y.ToString()).Contains(x)))
1230+
else if (Array.Exists(PingerHelper.CleanBrowsingAdultDNSv4, x => _currentDNS.Select(y => y.ToString()).Contains(x)))
12311231
{
12321232
boxDNS.Text = Constants.CleanBrowsingAdultFilterDNS;
12331233
return;
@@ -1318,7 +1318,7 @@ private void ApplyCustomDNS()
13181318
txtDns6B.Text
13191319
};
13201320

1321-
if (customDns4.Any(x => string.IsNullOrEmpty(x)) || customDns6.Any(x => string.IsNullOrEmpty(x)))
1321+
if (Array.Exists(customDns4, x => string.IsNullOrEmpty(x)) || Array.Exists(customDns6, x => string.IsNullOrEmpty(x)))
13221322
{
13231323
return;
13241324
}
@@ -2223,9 +2223,9 @@ private void Translate(bool skipFull = false)
22232223

22242224
if (element == null) continue;
22252225

2226-
if (element is ToggleCard)
2226+
if (element is ToggleCard tc)
22272227
{
2228-
((ToggleCard)element).LabelText = x.Value;
2228+
tc.LabelText = x.Value;
22292229
continue;
22302230
}
22312231

@@ -3352,7 +3352,7 @@ private void chkSelectAllModernApps_CheckedChanged(object sender, EventArgs e)
33523352
{
33533353
foreach (Control c in Utilities.GetSelfAndChildrenRecursive(panelUwp))
33543354
{
3355-
if (c is MoonCheck) ((MoonCheck)c).Checked = chkSelectAllModernApps.Checked;
3355+
if (c is MoonCheck mc) mc.Checked = chkSelectAllModernApps.Checked;
33563356
}
33573357
}
33583358

@@ -3833,7 +3833,7 @@ private async void btnDownloadApps_Click(object sender, EventArgs e)
38333833
{
38343834
if (string.IsNullOrEmpty(x.Tag)) continue;
38353835
temp = appsTab.Controls.Find(x.Tag, true);
3836-
if (temp.Count() == 0) continue;
3836+
if (!temp.Any()) continue;
38373837
currentCheck = (MoonCheck)temp[0];
38383838
if (currentCheck == null) continue;
38393839
if (!currentCheck.Checked) continue;

Optimizer/Forms/StartupRestoreForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private void RefreshBackups()
3838
listRestoreItems.Items.Add(Path.GetFileNameWithoutExtension(x));
3939
}
4040

41-
if (_backups.Count() > 0) listRestoreItems.SelectedIndex = 0;
41+
if (_backups.Any()) listRestoreItems.SelectedIndex = 0;
4242
}
4343

4444
private void Translate()

Optimizer/SilentOps.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ internal static void ProcessPinger()
171171
{
172172
bool atLeastOnePrimary4 = CurrentSilentConfig.Pinger.CustomDNSv4.Length > 0 && CurrentSilentConfig.Pinger.CustomDNSv4.Length < 3;
173173
bool atLeastOnePrimary6 = CurrentSilentConfig.Pinger.CustomDNSv6.Length > 0 && CurrentSilentConfig.Pinger.CustomDNSv6.Length < 3;
174-
bool notEmptyDNS4 = CurrentSilentConfig.Pinger.CustomDNSv4.Any(x => !string.IsNullOrEmpty(x));
175-
bool notEmptyDNS6 = CurrentSilentConfig.Pinger.CustomDNSv6.Any(x => !string.IsNullOrEmpty(x));
174+
bool notEmptyDNS4 = Array.Exists(CurrentSilentConfig.Pinger.CustomDNSv4, (x => !string.IsNullOrEmpty(x)));
175+
bool notEmptyDNS6 = Array.Exists(CurrentSilentConfig.Pinger.CustomDNSv6, (x => !string.IsNullOrEmpty(x)));
176176

177177
if (atLeastOnePrimary4 && atLeastOnePrimary6 && notEmptyDNS4 && notEmptyDNS6)
178178
{

Optimizer/UWPHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal static List<KeyValuePair<string, string>> GetUWPApps(bool showAll)
4242
foreach (PSObject x in psResult)
4343
{
4444
tmp = x.ToString().Replace("@", string.Empty).Replace("{", string.Empty).Replace("}", string.Empty).Replace("Name=", string.Empty).Replace("InstallLocation=", string.Empty).Trim().Split(';');
45-
if (!modernApps.Any(i => i.Key == tmp[0]))
45+
if (!modernApps.Exists(i => i.Key == tmp[0]))
4646
{
4747
modernApps.Add(new KeyValuePair<string, string>(tmp[0], tmp[1]));
4848
}

Optimizer/Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ internal static void ActivateMainForm()
257257

258258
internal static bool ServiceExists(string serviceName)
259259
{
260-
return ServiceController.GetServices().Any(serviceController => serviceController.ServiceName.Equals(serviceName));
260+
return Array.Exists(ServiceController.GetServices(), (serviceController => serviceController.ServiceName.Equals(serviceName)));
261261
}
262262

263263
internal static void StopService(string serviceName)

0 commit comments

Comments
 (0)