|
28 | 28 | from coverage.debug import NoDebugging, auto_repr, file_summary |
29 | 29 | from coverage.exceptions import CoverageException, DataError |
30 | 30 | from coverage.misc import Hasher, file_be_gone, isolate_module |
31 | | -from coverage.numbits import numbits_to_nums, numbits_union, nums_to_numbits |
| 31 | +from coverage.numbits import ( |
| 32 | + numbits_to_nums, |
| 33 | + numbits_union, |
| 34 | + nums_to_numbits, |
| 35 | + register_sqlite_functions, |
| 36 | +) |
32 | 37 | from coverage.sqlitedb import SqliteDb |
33 | 38 | from coverage.types import AnyCallable, FilePath, TArc, TDebugCtl, TLineNo, TWarnFn |
34 | 39 | from coverage.version import __version__ |
@@ -128,25 +133,6 @@ def _wrapped(self: CoverageData, *args: Any, **kwargs: Any) -> Any: |
128 | 133 | return _wrapped |
129 | 134 |
|
130 | 135 |
|
131 | | -class NumbitsUnionAgg: |
132 | | - """SQLite aggregate function for computing union of numbits.""" |
133 | | - |
134 | | - def __init__(self) -> None: |
135 | | - self.result = 0 |
136 | | - self.result_nbytes = 0 |
137 | | - |
138 | | - def step(self, value: bytes) -> None: |
139 | | - """Process one value in the aggregation.""" |
140 | | - self.result |= int.from_bytes(value, "little") |
141 | | - self.result_nbytes = max(self.result_nbytes, len(value)) |
142 | | - |
143 | | - def finalize(self) -> bytes: |
144 | | - """Return the final aggregated result.""" |
145 | | - if not self.result_nbytes: |
146 | | - return b"" |
147 | | - return self.result.to_bytes(self.result_nbytes, "little") |
148 | | - |
149 | | - |
150 | 136 | class CoverageData: |
151 | 137 | """Manages collected coverage data, including file storage. |
152 | 138 |
|
@@ -750,13 +736,8 @@ def update( |
750 | 736 | con.con.isolation_level = "IMMEDIATE" |
751 | 737 |
|
752 | 738 | # Register functions for SQLite |
753 | | - con.con.create_function("numbits_union", 2, numbits_union) |
| 739 | + register_sqlite_functions(con.con) |
754 | 740 | con.con.create_function("map_path", 1, map_path) |
755 | | - con.con.create_aggregate( |
756 | | - "numbits_union_agg", |
757 | | - 1, |
758 | | - NumbitsUnionAgg, # type: ignore[arg-type] |
759 | | - ) |
760 | 741 |
|
761 | 742 | # Attach the other database |
762 | 743 | con.execute_void("ATTACH DATABASE ? AS other_db", (other_data.data_filename(),)) |
|
0 commit comments