From 09120284c50234668f2215cc7c26550fdaf90add Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Sun, 23 Feb 2014 22:57:29 +0100 Subject: [PATCH] Cache relative paths instead of using an angular filter. This will improve the performance a lot. First load performance may suffer a bit, though. Also, the leading "./" is skipped now, as this causes additional string ops, which turn out to be particularly harmful in some cases (slots vs heaps aka. shortstrings in spidermonkey, allocation overhead). And the leading "./" is not really required anymore. --- index.html | 3 +-- js/ctrls/download.js | 17 ++++++++++++++--- js/filters/path.js | 8 -------- js/init.js | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) delete mode 100644 js/filters/path.js diff --git a/index.html b/index.html index 9d30c60..a30f28e 100755 --- a/index.html +++ b/index.html @@ -50,7 +50,6 @@ - @@ -508,7 +507,7 @@
  • Length  {{download.pieceLength | blength}}
  • diff --git a/js/ctrls/download.js b/js/ctrls/download.js index ee175ef..d7635a3 100644 --- a/js/ctrls/download.js +++ b/js/ctrls/download.js @@ -12,6 +12,10 @@ function( scope, rpc, utils, alerts, modals, fsettings, activeInclude, waitingExclude, window ) { + + var re_slashes = /\\/g; + var slash = "/"; + scope.active = [], scope.waiting = [], scope.stopped = []; scope.gstats = {}; @@ -192,9 +196,16 @@ function( if (files) { var cfiles = ctx["files"] || (ctx["files"] = []); for (var i = 0; i < files.length; ++i) { - var file = cfiles[i] || (cfiles[i] = {}); - file.path = files[i].path; - file.length = files[i].length; + var cfile = cfiles[i] || (cfiles[i] = {}); + var file = files[i]; + if (file.path !== cfile.path) { + cfile.path = file.path; + cfile.length = file.length; + cfile.relpath = file.path.replace(re_slashes, slash); + if (!cfile.relpath.startsWith("[")) { // METADATA + cfile.relpath = cfile.relpath.substr(ctx.dir.length + 1); + } + } } cfiles.length = files.length; } diff --git a/js/filters/path.js b/js/filters/path.js deleted file mode 100644 index d3ef1ea..0000000 --- a/js/filters/path.js +++ /dev/null @@ -1,8 +0,0 @@ -// returns the relative path from base -angular.module('webui.filters.path', []) -.filter('prelative', function() { - return function(path, base) { - return path.replace(/\\/g, '/') - .replace(base.replace(/\\/, '/'), '.'); - }; -}); diff --git a/js/init.js b/js/init.js index 3090551..25b44e0 100644 --- a/js/init.js +++ b/js/init.js @@ -3,7 +3,7 @@ var webui = angular.module('webui', [ 'webui.services.constants', 'webui.services.rpc', 'webui.services.modals', 'webui.services.alerts', 'webui.services.settings', 'webui.services.settings.filters', - 'webui.filters.bytes', 'webui.filters.path', + 'webui.filters.bytes', 'webui.directives.chunkbar', 'webui.directives.dgraph', 'webui.directives.fselect', 'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal', 'webui.ctrls.alert', 'webui.ctrls.props',