Skip to content

Commit f366820

Browse files
committed
Small optimizations to combine
a) Avoid copying lists in executemany_void: while some callers provide an iterator, others were already providing a list and in that case we had to copy it b) Avoid unpacking and re-packing contexts In total this shaves about 10% of the combine time in pyca/cryptography's CI
1 parent 2e9a18d commit f366820

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

coverage/sqldata.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def update(
685685

686686
# Get contexts data.
687687
with con.execute("select context from context") as cur:
688-
contexts = [context for (context,) in cur]
688+
contexts = cur.fetchall()
689689

690690
# Get arc data.
691691
with con.execute(
@@ -743,14 +743,14 @@ def update(
743743
# Create all file and context rows in the DB.
744744
con.executemany_void(
745745
"insert or ignore into file (path) values (?)",
746-
((file,) for file in files.values()),
746+
[(file,) for file in files.values()],
747747
)
748748
with con.execute("select id, path from file") as cur:
749749
file_ids = {path: id for id, path in cur}
750750
self._file_map.update(file_ids)
751751
con.executemany_void(
752752
"insert or ignore into context (context) values (?)",
753-
((context,) for context in contexts),
753+
contexts,
754754
)
755755
with con.execute("select id, context from context") as cur:
756756
context_ids = {context: id for id, context in cur}
@@ -778,10 +778,10 @@ def update(
778778
if arcs:
779779
self._choose_lines_or_arcs(arcs=True)
780780

781-
arc_rows = (
781+
arc_rows = [
782782
(file_ids[file], context_ids[context], fromno, tono)
783783
for file, context, fromno, tono in arcs
784-
)
784+
]
785785

786786
# Write the combined data.
787787
con.executemany_void(
@@ -813,7 +813,7 @@ def update(
813813

814814
con.executemany_void(
815815
"insert or ignore into tracer (file_id, tracer) values (?, ?)",
816-
((file_ids[filename], tracer) for filename, tracer in tracer_map.items()),
816+
[(file_ids[filename], tracer) for filename, tracer in tracer_map.items()],
817817
)
818818

819819
if not self._no_disk:

coverage/sqlitedb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,8 @@ def _executemany(self, sql: str, data: list[Any]) -> sqlite3.Cursor:
210210
# https://github.com/nedbat/coveragepy/issues/1010
211211
return self.con.executemany(sql, data)
212212

213-
def executemany_void(self, sql: str, data: Iterable[Any]) -> None:
213+
def executemany_void(self, sql: str, data: list[Any]) -> None:
214214
"""Same as :meth:`python:sqlite3.Connection.executemany` when you don't need the cursor."""
215-
data = list(data)
216215
if data:
217216
self._executemany(sql, data).close()
218217

0 commit comments

Comments
 (0)