aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@err.no>2016-10-03 21:10:07 +0200
committerTollef Fog Heen <tfheen@err.no>2016-10-03 21:10:07 +0200
commit128f1dc945790cffd65a874d6746644ac919ba2a (patch)
treec9515e9b227c965106f5d49f7727e95e9c81739f /wee_slack.py
parent6057232b126c23bb0a97e0efad7c02e448089548 (diff)
downloadwee-slack-128f1dc945790cffd65a874d6746644ac919ba2a.tar.gz
Performance: pass in item to update
When adding an item to the hash table, pass in the updated item, which saves a bunch of work.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 8461840..fe18ac9 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -101,14 +101,24 @@ class SearchList(list):
def append(self, item, aliases=[]):
super(SearchList, self).append(item)
- self.update_hashtable()
+ self.update_hashtable(item)
- def update_hashtable(self):
- for child in self:
- if hasattr(child, "get_aliases"):
- for alias in child.get_aliases():
+ def update_hashtable(self, item=None):
+ if item is not None:
+ try:
+ for alias in item.get_aliases():
if alias is not None:
- self.hashtable[alias] = child
+ self.hashtable[alias] = item
+ except AttributeError:
+ pass
+ else:
+ for child in self:
+ try:
+ for alias in child.get_aliases():
+ if alias is not None:
+ self.hashtable[alias] = child
+ except AttributeError:
+ pass
def find_by_class(self, class_name):
items = []