Move to lists and arrays for more performant iterating

This commit is contained in:
Kyle Spearrin 2016-08-17 21:19:19 -04:00
parent ca4a00196a
commit 8579b7130a
2 changed files with 15 additions and 9 deletions

View file

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using Bit.App.Resources;
using Bit.App.Utilities;
using System.Linq;
namespace Bit.App.Models.Page
{
@ -36,7 +34,7 @@ namespace Bit.App.Models.Page
Name = folder.Name?.Decrypt();
}
public Folder(IEnumerable<Site> sites)
public Folder(List<Site> sites)
{
AddRange(sites);
}

View file

@ -53,8 +53,8 @@ namespace Bit.App.Pages
public ExtendedObservableCollection<VaultListPageModel.Folder> PresentationFolders { get; private set; }
= new ExtendedObservableCollection<VaultListPageModel.Folder>();
public ListView ListView { get; set; }
public IEnumerable<VaultListPageModel.Site> Sites { get; set; } = new List<VaultListPageModel.Site>();
public IEnumerable<VaultListPageModel.Folder> Folders { get; set; } = new List<VaultListPageModel.Folder>();
public VaultListPageModel.Site[] Sites { get; set; } = new VaultListPageModel.Site[] { };
public VaultListPageModel.Folder[] Folders { get; set; } = new VaultListPageModel.Folder[] { };
public SearchBar Search { get; set; }
private void Init()
@ -166,7 +166,7 @@ namespace Bit.App.Pages
var filteredSites = Sites
.Where(s => s.Name.ToLower().Contains(searchFilter) || s.Username.ToLower().Contains(searchFilter))
.TakeWhile(s => !ct.IsCancellationRequested)
.ToList();
.ToArray();
ct.ThrowIfCancellationRequested();
LoadFolders(filteredSites, ct);
@ -237,8 +237,16 @@ namespace Bit.App.Pages
var folders = await foldersTask;
var sites = await sitesTask;
Folders = folders.Select(f => new VaultListPageModel.Folder(f)).OrderBy(s => s.Name);
Sites = sites.Select(s => new VaultListPageModel.Site(s)).OrderBy(s => s.Name).ThenBy(s => s.Username);
Folders = folders
.Select(f => new VaultListPageModel.Folder(f))
.OrderBy(s => s.Name)
.ToArray();
Sites = sites
.Select(s => new VaultListPageModel.Site(s))
.OrderBy(s => s.Name)
.ThenBy(s => s.Username)
.ToArray();
try
{
@ -250,7 +258,7 @@ namespace Bit.App.Pages
return cts;
}
private void LoadFolders(IEnumerable<VaultListPageModel.Site> sites, CancellationToken ct)
private void LoadFolders(VaultListPageModel.Site[] sites, CancellationToken ct)
{
var folders = new List<VaultListPageModel.Folder>(Folders);