Commit 32bb3b90 authored by dpapad's avatar dpapad Committed by Commit Bot

MD Extensions: Drop unnecessary work when first populating the list.

During initial population of the extensions and apps lists, addItem()
was called N times, which internally performs a linear search N times,
as well as triggres splice() notifications that are unnecessary.

As revealed by DevTools (for a total of 30 extensions and apps):
 - before: the N calls to addItem() were taking ~22ms total
 - after: The initialization of the lists takes ~5ms total 

Bug: 764126
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: If66d752cd3e7ac4b4ecd01ea4964ca6fd8d8f0db
Reviewed-on: https://chromium-review.googlesource.com/746967Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512989}
parent 7917059b
......@@ -248,6 +248,24 @@ cr.define('extensions', function() {
this.apps[this.getIndexInList_('apps', id)];
},
/**
* Categorizes |items| to apps and extensions and initializes those lists.
* This is faster than calling |addItem| multiple times.
* @param {!Array<!chrome.developerPrivate.ExtensionInfo>} items
*/
initAppsAndExtensions(items) {
items.sort(compareExtensions);
let apps = [];
let extensions = [];
for (let i of items) {
let list = this.getListId_(i) === 'apps' ? apps : extensions;
list.push(i);
}
this.apps = apps;
this.extensions = extensions;
},
/**
* Creates and adds a new extensions-item element to the list, inserting it
* into its sorted position in the relevant section.
......
......@@ -44,9 +44,7 @@ cr.define('extensions', function() {
chrome.developerPrivate.getExtensionsInfo(
{includeDisabled: true, includeTerminated: true}, extensions => {
this.extensions_ = extensions;
for (let extension of extensions)
this.manager_.addItem(extension);
this.manager_.initAppsAndExtensions(extensions);
this.manager_.initPage();
});
chrome.developerPrivate.getProfileConfiguration(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment