Skip to content

Commit 0289a21

Browse files
committed
Improve re2
1 parent daff5f2 commit 0289a21

15 files changed

Lines changed: 273 additions & 300 deletions

benchmarks/bench_pathspec_many_to_many.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from pathspec import (
1414
PathSpec)
15-
from pathspec._backends.re2.pathspec import (
16-
Re2PsBackend)
1715
from pathspec._backends.simple.pathspec import (
1816
SimplePsBackend)
1917
from benchmarks.match_pathspec import (
@@ -105,7 +103,7 @@ def bench_hs_v1(
105103
# Re2 backend.
106104

107105
@pytest.mark.benchmark(group=GROUP)
108-
def bench_re2_filtered(
106+
def bench_re2_v1(
109107
benchmark: BenchmarkFixture,
110108
cpython_files: set[str],
111109
cpython_gi_lines_all: list[str],
@@ -114,52 +112,6 @@ def bench_re2_filtered(
114112
'gitwildmatch',
115113
cpython_gi_lines_all,
116114
backend='re2',
117-
_test_backend_factory=partial(Re2PsBackend, no_reverse=True)
118-
)
119-
benchmark(run_match, spec, cpython_files)
120-
121-
122-
@pytest.mark.benchmark(group=GROUP)
123-
def bench_re2_filtered_reversed(
124-
benchmark: BenchmarkFixture,
125-
cpython_files: set[str],
126-
cpython_gi_lines_all: list[str],
127-
):
128-
spec = PathSpec.from_lines(
129-
'gitwildmatch',
130-
cpython_gi_lines_all,
131-
backend='re2',
132-
_test_backend_factory=Re2PsBackend,
133-
)
134-
benchmark(run_match, spec, cpython_files)
135-
136-
137-
@pytest.mark.benchmark(group=GROUP)
138-
def bench_re2_unfiltered(
139-
benchmark: BenchmarkFixture,
140-
cpython_files: set[str],
141-
cpython_gi_lines_all: list[str],
142-
):
143-
spec = PathSpec.from_lines(
144-
'gitwildmatch',
145-
cpython_gi_lines_all,
146-
backend='re2',
147-
_test_backend_factory=partial(Re2PsBackend, no_filter=True, no_reverse=True)
148-
)
149-
benchmark(run_match, spec, cpython_files)
150-
151-
152-
@pytest.mark.benchmark(group=GROUP)
153-
def bench_re2_unfiltered_reversed(
154-
benchmark: BenchmarkFixture,
155-
cpython_files: set[str],
156-
cpython_gi_lines_all: list[str],
157-
):
158-
spec = PathSpec.from_lines(
159-
'gitwildmatch',
160-
cpython_gi_lines_all,
161-
backend='re2',
162-
_test_backend_factory=partial(Re2PsBackend, no_filter=True)
163115
)
164116
benchmark(run_match, spec, cpython_files)
165117

benchmarks/bench_pathspec_many_to_one_end.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from pathspec import (
1414
PathSpec)
15-
from pathspec._backends.re2.pathspec import (
16-
Re2PsBackend)
1715
from pathspec._backends.simple.pathspec import (
1816
SimplePsBackend)
1917
from benchmarks.match_pathspec import (
@@ -88,7 +86,7 @@ def bench_hs_v1(
8886
# Re2 backend.
8987

9088
@pytest.mark.benchmark(group=GROUP)
91-
def bench_re2_filtered(
89+
def bench_re2_v1(
9290
benchmark: BenchmarkFixture,
9391
cpython_file_match_end: str,
9492
cpython_gi_lines_all: list[str],
@@ -97,52 +95,6 @@ def bench_re2_filtered(
9795
'gitwildmatch',
9896
cpython_gi_lines_all,
9997
backend='re2',
100-
_test_backend_factory=partial(Re2PsBackend, no_reverse=True)
101-
)
102-
benchmark(run_match, spec, cpython_file_match_end)
103-
104-
105-
@pytest.mark.benchmark(group=GROUP)
106-
def bench_re2_filtered_reversed(
107-
benchmark: BenchmarkFixture,
108-
cpython_file_match_end: str,
109-
cpython_gi_lines_all: list[str],
110-
):
111-
spec = PathSpec.from_lines(
112-
'gitwildmatch',
113-
cpython_gi_lines_all,
114-
backend='re2',
115-
_test_backend_factory=Re2PsBackend,
116-
)
117-
benchmark(run_match, spec, cpython_file_match_end)
118-
119-
120-
@pytest.mark.benchmark(group=GROUP)
121-
def bench_re2_unfiltered(
122-
benchmark: BenchmarkFixture,
123-
cpython_file_match_end: str,
124-
cpython_gi_lines_all: list[str],
125-
):
126-
spec = PathSpec.from_lines(
127-
'gitwildmatch',
128-
cpython_gi_lines_all,
129-
backend='re2',
130-
_test_backend_factory=partial(Re2PsBackend, no_filter=True, no_reverse=True)
131-
)
132-
benchmark(run_match, spec, cpython_file_match_end)
133-
134-
135-
@pytest.mark.benchmark(group=GROUP)
136-
def bench_re2_unfiltered_reversed(
137-
benchmark: BenchmarkFixture,
138-
cpython_file_match_end: str,
139-
cpython_gi_lines_all: list[str],
140-
):
141-
spec = PathSpec.from_lines(
142-
'gitwildmatch',
143-
cpython_gi_lines_all,
144-
backend='re2',
145-
_test_backend_factory=partial(Re2PsBackend, no_filter=True)
14698
)
14799
benchmark(run_match, spec, cpython_file_match_end)
148100

benchmarks/bench_pathspec_many_to_one_middle.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from pathspec import (
1414
PathSpec)
15-
from pathspec._backends.re2.pathspec import (
16-
Re2PsBackend)
1715
from pathspec._backends.simple.pathspec import (
1816
SimplePsBackend)
1917
from benchmarks.match_pathspec import (
@@ -88,7 +86,7 @@ def bench_hs_v1(
8886
# Re2 backend.
8987

9088
@pytest.mark.benchmark(group=GROUP)
91-
def bench_re2_filtered(
89+
def bench_re2_v1(
9290
benchmark: BenchmarkFixture,
9391
cpython_file_match_middle: str,
9492
cpython_gi_lines_all: list[str],
@@ -97,52 +95,6 @@ def bench_re2_filtered(
9795
'gitwildmatch',
9896
cpython_gi_lines_all,
9997
backend='re2',
100-
_test_backend_factory=partial(Re2PsBackend, no_reverse=True)
101-
)
102-
benchmark(run_match, spec, cpython_file_match_middle)
103-
104-
105-
@pytest.mark.benchmark(group=GROUP)
106-
def bench_re2_filtered_reversed(
107-
benchmark: BenchmarkFixture,
108-
cpython_file_match_middle: str,
109-
cpython_gi_lines_all: list[str],
110-
):
111-
spec = PathSpec.from_lines(
112-
'gitwildmatch',
113-
cpython_gi_lines_all,
114-
backend='re2',
115-
_test_backend_factory=Re2PsBackend,
116-
)
117-
benchmark(run_match, spec, cpython_file_match_middle)
118-
119-
120-
@pytest.mark.benchmark(group=GROUP)
121-
def bench_re2_unfiltered(
122-
benchmark: BenchmarkFixture,
123-
cpython_file_match_middle: str,
124-
cpython_gi_lines_all: list[str],
125-
):
126-
spec = PathSpec.from_lines(
127-
'gitwildmatch',
128-
cpython_gi_lines_all,
129-
backend='re2',
130-
_test_backend_factory=partial(Re2PsBackend, no_filter=True, no_reverse=True)
131-
)
132-
benchmark(run_match, spec, cpython_file_match_middle)
133-
134-
135-
@pytest.mark.benchmark(group=GROUP)
136-
def bench_re2_unfiltered_reversed(
137-
benchmark: BenchmarkFixture,
138-
cpython_file_match_middle: str,
139-
cpython_gi_lines_all: list[str],
140-
):
141-
spec = PathSpec.from_lines(
142-
'gitwildmatch',
143-
cpython_gi_lines_all,
144-
backend='re2',
145-
_test_backend_factory=partial(Re2PsBackend, no_filter=True)
14698
)
14799
benchmark(run_match, spec, cpython_file_match_middle)
148100

benchmarks/bench_pathspec_many_to_one_none.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def bench_hs_v1(
8888
# Re2 backend.
8989

9090
@pytest.mark.benchmark(group=GROUP)
91-
def bench_re2_filtered(
91+
def bench_re2_v1(
9292
benchmark: BenchmarkFixture,
9393
cpython_file_match_none: str,
9494
cpython_gi_lines_all: list[str],
@@ -97,52 +97,6 @@ def bench_re2_filtered(
9797
'gitwildmatch',
9898
cpython_gi_lines_all,
9999
backend='re2',
100-
_test_backend_factory=partial(Re2PsBackend, no_reverse=True)
101-
)
102-
benchmark(run_match, spec, cpython_file_match_none)
103-
104-
105-
@pytest.mark.benchmark(group=GROUP)
106-
def bench_re2_filtered_reversed(
107-
benchmark: BenchmarkFixture,
108-
cpython_file_match_none: str,
109-
cpython_gi_lines_all: list[str],
110-
):
111-
spec = PathSpec.from_lines(
112-
'gitwildmatch',
113-
cpython_gi_lines_all,
114-
backend='re2',
115-
_test_backend_factory=Re2PsBackend,
116-
)
117-
benchmark(run_match, spec, cpython_file_match_none)
118-
119-
120-
@pytest.mark.benchmark(group=GROUP)
121-
def bench_re2_unfiltered(
122-
benchmark: BenchmarkFixture,
123-
cpython_file_match_none: str,
124-
cpython_gi_lines_all: list[str],
125-
):
126-
spec = PathSpec.from_lines(
127-
'gitwildmatch',
128-
cpython_gi_lines_all,
129-
backend='re2',
130-
_test_backend_factory=partial(Re2PsBackend, no_filter=True, no_reverse=True)
131-
)
132-
benchmark(run_match, spec, cpython_file_match_none)
133-
134-
135-
@pytest.mark.benchmark(group=GROUP)
136-
def bench_re2_unfiltered_reversed(
137-
benchmark: BenchmarkFixture,
138-
cpython_file_match_none: str,
139-
cpython_gi_lines_all: list[str],
140-
):
141-
spec = PathSpec.from_lines(
142-
'gitwildmatch',
143-
cpython_gi_lines_all,
144-
backend='re2',
145-
_test_backend_factory=partial(Re2PsBackend, no_filter=True)
146100
)
147101
benchmark(run_match, spec, cpython_file_match_none)
148102

benchmarks/bench_pathspec_many_to_one_start.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from pathspec import (
1414
PathSpec)
15-
from pathspec._backends.re2.pathspec import (
16-
Re2PsBackend)
1715
from pathspec._backends.simple.pathspec import (
1816
SimplePsBackend)
1917
from benchmarks.match_pathspec import (
@@ -88,7 +86,7 @@ def bench_hs_v1(
8886
# Re2 backend.
8987

9088
@pytest.mark.benchmark(group=GROUP)
91-
def bench_re2_filtered(
89+
def bench_re2_v1(
9290
benchmark: BenchmarkFixture,
9391
cpython_file_match_start: str,
9492
cpython_gi_lines_all: list[str],
@@ -97,52 +95,6 @@ def bench_re2_filtered(
9795
'gitwildmatch',
9896
cpython_gi_lines_all,
9997
backend='re2',
100-
_test_backend_factory=partial(Re2PsBackend, no_reverse=True)
101-
)
102-
benchmark(run_match, spec, cpython_file_match_start)
103-
104-
105-
@pytest.mark.benchmark(group=GROUP)
106-
def bench_re2_filtered_reversed(
107-
benchmark: BenchmarkFixture,
108-
cpython_file_match_start: str,
109-
cpython_gi_lines_all: list[str],
110-
):
111-
spec = PathSpec.from_lines(
112-
'gitwildmatch',
113-
cpython_gi_lines_all,
114-
backend='re2',
115-
_test_backend_factory=Re2PsBackend,
116-
)
117-
benchmark(run_match, spec, cpython_file_match_start)
118-
119-
120-
@pytest.mark.benchmark(group=GROUP)
121-
def bench_re2_unfiltered(
122-
benchmark: BenchmarkFixture,
123-
cpython_file_match_start: str,
124-
cpython_gi_lines_all: list[str],
125-
):
126-
spec = PathSpec.from_lines(
127-
'gitwildmatch',
128-
cpython_gi_lines_all,
129-
backend='re2',
130-
_test_backend_factory=partial(Re2PsBackend, no_filter=True, no_reverse=True)
131-
)
132-
benchmark(run_match, spec, cpython_file_match_start)
133-
134-
135-
@pytest.mark.benchmark(group=GROUP)
136-
def bench_re2_unfiltered_reversed(
137-
benchmark: BenchmarkFixture,
138-
cpython_file_match_start: str,
139-
cpython_gi_lines_all: list[str],
140-
):
141-
spec = PathSpec.from_lines(
142-
'gitwildmatch',
143-
cpython_gi_lines_all,
144-
backend='re2',
145-
_test_backend_factory=partial(Re2PsBackend, no_filter=True)
14698
)
14799
benchmark(run_match, spec, cpython_file_match_start)
148100

benchmarks/match_gitignore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def _init_db(
322322
db: hyperscan.Database,
323323
debug: bool,
324324
patterns: list[tuple[int, RegexPattern]],
325-
sort_exprs: Optional[Callable[[list], None]],
325+
sort_ids: Optional[Callable[[list[int]], None]],
326326
) -> list[HyperscanExprDat]:
327327
# NOTICE: This is the current implementation.
328328

benchmarks/match_pathspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _init_db(
3939
db: hyperscan.Database,
4040
debug: bool,
4141
patterns: list[tuple[int, RegexPattern]],
42-
sort_exprs: Optional[Callable[[list], None]],
42+
sort_ids: Optional[Callable[[list[int]], None]],
4343
) -> list[HyperscanExprDat]:
4444
# NOTICE: This is the current implementation.
4545

pathspec/_backends/hyperscan/gitignore.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _init_db(
7979
db: hyperscan.Database,
8080
debug: bool,
8181
patterns: list[tuple[int, RegexPattern]],
82-
sort_exprs: Optional[Callable[[list], None]],
82+
sort_ids: Optional[Callable[[list[int]], None]],
8383
) -> list[HyperscanExprDat]:
8484
"""
8585
Create the Hyperscan database from the given patterns.
@@ -92,9 +92,9 @@ def _init_db(
9292
*patterns* (:class:`~collections.abc.Sequence` of :class:`.RegexPattern`)
9393
contains the patterns.
9494
95-
*sort_exprs* (:class:`callable` or :data:`None`) is a function used to sort
96-
the compiled expressions. This is used during testing to ensure the order of
97-
expressions is not accidentally relied on.
95+
*sort_ids* (:class:`callable` or :data:`None`) is a function used to sort
96+
the compiled expression ids. This is used during testing to ensure the order
97+
of expressions is not accidentally relied on.
9898
9999
Returns a :class:`list` indexed by expression id (:class:`int`) to its data
100100
(:class:`HyperscanExprDat`).
@@ -162,8 +162,8 @@ def _init_db(
162162

163163
# Sort expressions.
164164
ids = list(range(len(exprs)))
165-
if sort_exprs is not None:
166-
sort_exprs(ids)
165+
if sort_ids is not None:
166+
sort_ids(ids)
167167
exprs = [exprs[__id] for __id in ids]
168168

169169
# Compile patterns.

0 commit comments

Comments
 (0)