From 5a8006afef1430fb8456c1827c00707fdf58cfb5 Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Wed, 17 Apr 2024 09:08:22 -0400 Subject: [PATCH] [Backend] Use more efficient .Length/.Count check (#3050) --- Backend/Helper/Language.cs | 2 +- Backend/Services/LiftService.cs | 4 ++-- Backend/Services/StatisticsService.cs | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Backend/Helper/Language.cs b/Backend/Helper/Language.cs index 21e221a18b..cb5d9bd4d6 100644 --- a/Backend/Helper/Language.cs +++ b/Backend/Helper/Language.cs @@ -43,7 +43,7 @@ public static List ConvertLangTagsToWritingSystems(IEnumerable public static List GetWritingSystems(string dirPath) { - if (!Directory.GetFiles(dirPath, "*.ldml").Any()) + if (Directory.GetFiles(dirPath, "*.ldml").Length == 0) { dirPath = FileStorage.GenerateWritingsSystemsSubdirPath(dirPath); } diff --git a/Backend/Services/LiftService.cs b/Backend/Services/LiftService.cs index 670daa2282..b91974a744 100644 --- a/Backend/Services/LiftService.cs +++ b/Backend/Services/LiftService.cs @@ -33,7 +33,7 @@ public CombineLiftWriter(string path, ByteOrderStyle byteOrderStyle) : base(path protected override void InsertPronunciationIfNeeded( LexEntry entry, List propertiesAlreadyOutput) { - if (entry.Pronunciations.FirstOrDefault() is not null && entry.Pronunciations.First().Forms.Any()) + if (entry.Pronunciations.Count != 0 && entry.Pronunciations.First().Forms.Length != 0) { foreach (var phonetic in entry.Pronunciations) { @@ -218,7 +218,7 @@ public bool DeleteImport(string userId) /// A bool indicating whether a character set was added to the project. public async Task LdmlImport(string dirPath, IProjectRepository projRepo, Project project) { - if (!Directory.GetFiles(dirPath, "*.ldml").Any()) + if (Directory.GetFiles(dirPath, "*.ldml").Length == 0) { dirPath = FileStorage.GenerateWritingsSystemsSubdirPath(dirPath); } diff --git a/Backend/Services/StatisticsService.cs b/Backend/Services/StatisticsService.cs index 60cccf1789..1943568632 100644 --- a/Backend/Services/StatisticsService.cs +++ b/Backend/Services/StatisticsService.cs @@ -32,7 +32,7 @@ public async Task> GetSemanticDomainCounts(string proj List? domainTreeNodeList = await _domainRepo.GetAllSemanticDomainTreeNodes(lang); List wordList = await _wordRepo.GetFrontier(projectId); - if (domainTreeNodeList is null || !domainTreeNodeList.Any() || !wordList.Any()) + if (domainTreeNodeList is null || domainTreeNodeList.Count == 0 || wordList.Count == 0) { return new List(); } @@ -66,7 +66,7 @@ public async Task> GetWordsPerDayPerUserCounts(str new Dictionary(); Dictionary userNameIdDictionary = new Dictionary(); - if (!wordList.Any()) + if (wordList.Count == 0) { return new List(); } @@ -136,7 +136,7 @@ public async Task GetProgressEstimationLineChartRoot(string proje Dictionary totalCountDictionary = new Dictionary(); // If no schedule yet or wordList is empty, return empty ChartRootData - if (!schedule.Any() || !wordList.Any()) + if (schedule.Count == 0 || wordList.Count == 0) { return LineChartData; } @@ -177,7 +177,7 @@ public async Task GetProgressEstimationLineChartRoot(string proje } // If no semantic domain has Created, return empty ChartRootData - if (!totalCountDictionary.Any()) + if (totalCountDictionary.Count == 0) { return LineChartData; } @@ -261,7 +261,7 @@ public async Task GetLineChartRootData(string projectId) ChartRootData LineChartData = new ChartRootData(); List list = await GetWordsPerDayPerUserCounts(projectId); // if the list is null or empty return new ChartRootData to generate a empty Chart - if (list is null || !list.Any()) + if (list is null || list.Count == 0) { return LineChartData; }