From 8579b7130aaa3c5279b4a8787f2968147cecc746 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 17 Aug 2016 21:19:19 -0400 Subject: [PATCH] Move to lists and arrays for more performant iterating --- src/App/Models/Page/VaultListPageModel.cs | 4 +--- src/App/Pages/Vault/VaultListSitesPage.cs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/App/Models/Page/VaultListPageModel.cs b/src/App/Models/Page/VaultListPageModel.cs index 896f7c8b2..3a48d2458 100644 --- a/src/App/Models/Page/VaultListPageModel.cs +++ b/src/App/Models/Page/VaultListPageModel.cs @@ -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 sites) + public Folder(List sites) { AddRange(sites); } diff --git a/src/App/Pages/Vault/VaultListSitesPage.cs b/src/App/Pages/Vault/VaultListSitesPage.cs index b2463b3d9..8f0b7393b 100644 --- a/src/App/Pages/Vault/VaultListSitesPage.cs +++ b/src/App/Pages/Vault/VaultListSitesPage.cs @@ -53,8 +53,8 @@ namespace Bit.App.Pages public ExtendedObservableCollection PresentationFolders { get; private set; } = new ExtendedObservableCollection(); public ListView ListView { get; set; } - public IEnumerable Sites { get; set; } = new List(); - public IEnumerable Folders { get; set; } = new List(); + 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 sites, CancellationToken ct) + private void LoadFolders(VaultListPageModel.Site[] sites, CancellationToken ct) { var folders = new List(Folders);