Skip to content

Commit 2a142be

Browse files
committed
Improve Tracer performance
Small improvements, but this is called very very often while we're tracing and so even micro-optimisations are worth it.
1 parent ce9a797 commit 2a142be

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

hypothesis-python/src/hypothesis/internal/scrutineer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ def should_trace_file(fname):
3131

3232

3333
class Tracer:
34-
"""A super-simple line coverage tracer."""
34+
"""A super-simple branch coverage tracer."""
35+
36+
__slots__ = ("branches", "_previous_location")
3537

3638
def __init__(self):
3739
self.branches = set()
38-
self.prev = None
40+
self._previous_location = None
3941

4042
def trace(self, frame, event, arg):
4143
if event == "call":
4244
return self.trace
4345
elif event == "line":
4446
fname = frame.f_code.co_filename
4547
if should_trace_file(fname):
46-
self.branches.add((self.prev, (fname, frame.f_lineno)))
47-
self.prev = (fname, frame.f_lineno)
48+
current_location = (fname, frame.f_lineno)
49+
self.branches.add((self._previous_location, current_location))
50+
self._previous_location = current_location
4851

4952

5053
def get_explaining_locations(traces):

0 commit comments

Comments
 (0)