Skip to content

Commit

Permalink
[Backend] Use more efficient .Length/.Count check (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Apr 17, 2024
1 parent dea7e6c commit 5a8006a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Backend/Helper/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static List<WritingSystem> ConvertLangTagsToWritingSystems(IEnumerable<st
/// </summary>
public static List<WritingSystem> GetWritingSystems(string dirPath)
{
if (!Directory.GetFiles(dirPath, "*.ldml").Any())
if (Directory.GetFiles(dirPath, "*.ldml").Length == 0)
{
dirPath = FileStorage.GenerateWritingsSystemsSubdirPath(dirPath);
}
Expand Down
4 changes: 2 additions & 2 deletions Backend/Services/LiftService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CombineLiftWriter(string path, ByteOrderStyle byteOrderStyle) : base(path
protected override void InsertPronunciationIfNeeded(
LexEntry entry, List<string> 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)
{
Expand Down Expand Up @@ -218,7 +218,7 @@ public bool DeleteImport(string userId)
/// <returns> A bool indicating whether a character set was added to the project. </returns>
public async Task<bool> LdmlImport(string dirPath, IProjectRepository projRepo, Project project)
{
if (!Directory.GetFiles(dirPath, "*.ldml").Any())
if (Directory.GetFiles(dirPath, "*.ldml").Length == 0)
{
dirPath = FileStorage.GenerateWritingsSystemsSubdirPath(dirPath);
}
Expand Down
10 changes: 5 additions & 5 deletions Backend/Services/StatisticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<List<SemanticDomainCount>> GetSemanticDomainCounts(string proj
List<SemanticDomainTreeNode>? domainTreeNodeList = await _domainRepo.GetAllSemanticDomainTreeNodes(lang);
List<Word> 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<SemanticDomainCount>();
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task<List<WordsPerDayPerUserCount>> GetWordsPerDayPerUserCounts(str
new Dictionary<string, WordsPerDayPerUserCount>();
Dictionary<string, string> userNameIdDictionary = new Dictionary<string, string>();

if (!wordList.Any())
if (wordList.Count == 0)
{
return new List<WordsPerDayPerUserCount>();
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task<ChartRootData> GetProgressEstimationLineChartRoot(string proje
Dictionary<string, int> totalCountDictionary = new Dictionary<string, int>();

// 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;
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public async Task<ChartRootData> GetProgressEstimationLineChartRoot(string proje
}

// If no semantic domain has Created, return empty ChartRootData
if (!totalCountDictionary.Any())
if (totalCountDictionary.Count == 0)
{
return LineChartData;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task<ChartRootData> GetLineChartRootData(string projectId)
ChartRootData LineChartData = new ChartRootData();
List<WordsPerDayPerUserCount> 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;
}
Expand Down

0 comments on commit 5a8006a

Please sign in to comment.