diff options
author | Kenneth Hsu <kennethhsu@gmail.com> | 2018-10-07 02:02:36 +0300 |
---|---|---|
committer | Kenneth Hsu <kennethhsu@gmail.com> | 2018-10-07 02:20:18 +0300 |
commit | b824c86c7edf8d1aa7ea9df0a5ee6b75dec3e467 (patch) | |
tree | a1365016d870241117b0f988b92d5e7b9f4dcce4 /Duplicati/CommandLine/Commands.cs | |
parent | 0c1ac9c489de2a8a36641da234a5a28865348b4a (diff) |
Avoid unnecessary enumeration of collections.
This improves performance by using Any() to avoid unnecessary
enumeration of collections.
Diffstat (limited to 'Duplicati/CommandLine/Commands.cs')
-rw-r--r-- | Duplicati/CommandLine/Commands.cs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Duplicati/CommandLine/Commands.cs b/Duplicati/CommandLine/Commands.cs index 700831fbc..9537d4133 100644 --- a/Duplicati/CommandLine/Commands.cs +++ b/Duplicati/CommandLine/Commands.cs @@ -174,7 +174,7 @@ namespace Duplicati.CommandLine setup(i);
i.ListAffected(args, res =>
{
- if (res.Filesets != null && res.Filesets.Count() != 0)
+ if (res.Filesets != null && res.Filesets.Any())
{
outwriter.WriteLine("The following filesets are affected:");
foreach (var e in res.Filesets)
@@ -314,8 +314,8 @@ namespace Duplicati.CommandLine // try again with all-versions set
var compareFilter = Library.Utility.JoinedFilterExpression.Join(new Library.Utility.FilterExpression(args), filter);
var isRequestForFiles =
- !controlFiles && res.Filesets.Count() != 0 &&
- (res.Files == null || res.Files.Count() == 0) &&
+ !controlFiles && res.Filesets.Any() &&
+ (res.Files == null || !res.Files.Any()) &&
!compareFilter.Empty;
if (isRequestForFiles && !Library.Utility.Utility.ParseBoolOption(options, "all-versions"))
@@ -327,7 +327,7 @@ namespace Duplicati.CommandLine res = i.List(args, filter);
}
- if (res.Filesets.Count() != 0 && (res.Files == null || res.Files.Count() == 0) && compareFilter.Empty)
+ if (res.Filesets.Any() && (res.Files == null || !res.Files.Any()) && compareFilter.Empty)
{
outwriter.WriteLine("Listing filesets:");
@@ -345,11 +345,11 @@ namespace Duplicati.CommandLine }
else
{
- if (res.Filesets.Count() == 0)
+ if (!res.Filesets.Any())
{
outwriter.WriteLine("No time or version matched a fileset");
}
- else if (res.Files == null || res.Files.Count() == 0)
+ else if (res.Files == null || !res.Files.Any())
{
outwriter.WriteLine("Found {0} filesets, but no files matched", res.Filesets.Count());
}
@@ -396,7 +396,7 @@ namespace Duplicati.CommandLine args.RemoveAt(0);
var res = i.Delete();
- if (res.DeletedSets.Count() == 0)
+ if (!res.DeletedSets.Any())
{
outwriter.WriteLine(Strings.Program.NoFilesetsMatching);
}
@@ -519,7 +519,7 @@ namespace Duplicati.CommandLine if (output.FullResults)
Library.Utility.Utility.PrintSerializeObject(res, outwriter);
- if (res.Warnings.Count() > 0)
+ if (res.Warnings.Any())
return 2;
}
}
@@ -694,8 +694,8 @@ namespace Duplicati.CommandLine }
else
{
- var filtered = from n in result.Verifications where n.Value.Count() != 0 select n;
- if (filtered.Count() == 0)
+ var filtered = from n in result.Verifications where n.Value.Any() select n;
+ if (!filtered.Any())
{
outwriter.WriteLine("Examined {0} files and found no errors", totalFiles);
return 0;
|