Core: Cache external method in local variable for speedup

(inspired by browsing through Python source)
This commit is contained in:
Paulus Schoutsen 2014-01-19 21:39:13 -08:00
parent 2d78e951f7
commit ac0ca5d001

View File

@ -117,24 +117,24 @@ def track_time_change(bus, action,
hour=None, minute=None, second=None, hour=None, minute=None, second=None,
point_in_time=None, listen_once=False): point_in_time=None, listen_once=False):
""" Adds a listener that will listen for a specified or matching time. """ """ Adds a listener that will listen for a specified or matching time. """
year, month = _process_match_param(year), _process_match_param(month) pmp = _process_match_param
day = _process_match_param(day) year, month, day = pmp(year), pmp(month), pmp(day)
hour, minute, second = pmp(hour), pmp(minute), pmp(second)
hour, minute = _process_match_param(hour), _process_match_param(minute)
second = _process_match_param(second)
def listener(event): def listener(event):
""" Listens for matching time_changed events. """ """ Listens for matching time_changed events. """
now = event.data['now'] now = event.data['now']
mat = _matcher
if (point_in_time and now > point_in_time) or \ if (point_in_time and now > point_in_time) or \
(not point_in_time and (not point_in_time and
_matcher(now.year, year) and mat(now.year, year) and
_matcher(now.month, month) and mat(now.month, month) and
_matcher(now.day, day) and mat(now.day, day) and
_matcher(now.hour, hour) and mat(now.hour, hour) and
_matcher(now.minute, minute) and mat(now.minute, minute) and
_matcher(now.second, second)): mat(now.second, second)):
# point_in_time are exact points in time # point_in_time are exact points in time
# so we always remove it after fire # so we always remove it after fire