From 3be07ed24acb5f4f9972f6c2b1e21b158b25f1a3 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 7 May 2017 21:37:28 -0700 Subject: [PATCH] Remove split conversion to tuple Instead of needing to convert this from a list to a tuple on every property access just keep the internal split collection as a tuple in the first place (this saves time on every access of it). Change-Id: I7d216394a2dbb49aa8e6ed3705090bac29171907 --- oslo_utils/timeutils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oslo_utils/timeutils.py b/oslo_utils/timeutils.py index 2b38ead..d467972 100644 --- a/oslo_utils/timeutils.py +++ b/oslo_utils/timeutils.py @@ -416,7 +416,7 @@ class StopWatch(object): self._started_at = None self._stopped_at = None self._state = None - self._splits = [] + self._splits = () def start(self): """Starts the watch (if not already started). @@ -428,13 +428,13 @@ class StopWatch(object): self._started_at = now() self._stopped_at = None self._state = self._STARTED - self._splits = [] + self._splits = () return self @property def splits(self): """Accessor to all/any splits that have been captured.""" - return tuple(self._splits) + return self._splits def split(self): """Captures a split/elapsed since start time (and doesn't stop).""" @@ -444,7 +444,7 @@ class StopWatch(object): length = self._delta_seconds(self._splits[-1].elapsed, elapsed) else: length = elapsed - self._splits.append(Split(elapsed, length)) + self._splits = self._splits + (Split(elapsed, length),) return self._splits[-1] else: raise RuntimeError("Can not create a split time of a stopwatch"