1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-28 12:35:40 +01:00

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

View File

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