From 739c4de0ef44b503f7a6612b79303523412e16f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Fri, 7 Mar 2014 17:52:32 +0000 Subject: [PATCH] Add a isNicklistEmpty method to buffer model, speed up nicklist decision Flattening the nicklist is really unnecessary. This method is 10x faster for short nicklists, and much faster for buffers with lots of users. --- js/glowingbear.js | 4 ++-- js/models.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index ecb121a..7b21ed5 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -975,8 +975,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', if ($scope.nonicklist) { return false; } - // Use flat nicklist to check if empty - if (ab.flatNicklist().length === 0) { + // Check if nicklist is empty + if (ab.isNicklistEmpty()) { return false; } return true; diff --git a/js/models.js b/js/models.js index 427aa79..db330bd 100644 --- a/js/models.js +++ b/js/models.js @@ -147,6 +147,13 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) } }; + var isNicklistEmpty = function() { + for (var obj in nicklist) { + return false; + } + return true; + }; + return { id: pointer, fullName: fullName, @@ -171,7 +178,8 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) history: history, addToHistory: addToHistory, getHistoryUp: getHistoryUp, - getHistoryDown: getHistoryDown + getHistoryDown: getHistoryDown, + isNicklistEmpty: isNicklistEmpty }; };