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
This commit is contained in:
parent
f69aa3c386
commit
3be07ed24a
@ -416,7 +416,7 @@ class StopWatch(object):
|
|||||||
self._started_at = None
|
self._started_at = None
|
||||||
self._stopped_at = None
|
self._stopped_at = None
|
||||||
self._state = None
|
self._state = None
|
||||||
self._splits = []
|
self._splits = ()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Starts the watch (if not already started).
|
"""Starts the watch (if not already started).
|
||||||
@ -428,13 +428,13 @@ class StopWatch(object):
|
|||||||
self._started_at = now()
|
self._started_at = now()
|
||||||
self._stopped_at = None
|
self._stopped_at = None
|
||||||
self._state = self._STARTED
|
self._state = self._STARTED
|
||||||
self._splits = []
|
self._splits = ()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def splits(self):
|
def splits(self):
|
||||||
"""Accessor to all/any splits that have been captured."""
|
"""Accessor to all/any splits that have been captured."""
|
||||||
return tuple(self._splits)
|
return self._splits
|
||||||
|
|
||||||
def split(self):
|
def split(self):
|
||||||
"""Captures a split/elapsed since start time (and doesn't stop)."""
|
"""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)
|
length = self._delta_seconds(self._splits[-1].elapsed, elapsed)
|
||||||
else:
|
else:
|
||||||
length = elapsed
|
length = elapsed
|
||||||
self._splits.append(Split(elapsed, length))
|
self._splits = self._splits + (Split(elapsed, length),)
|
||||||
return self._splits[-1]
|
return self._splits[-1]
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Can not create a split time of a stopwatch"
|
raise RuntimeError("Can not create a split time of a stopwatch"
|
||||||
|
Loading…
Reference in New Issue
Block a user