Skip to content

Clear a merged range by its stored cells, not its advertised area - #9

Merged
almasumdev merged 1 commit into
almasumdev:mainfrom
cdeil:sparse-merge
Oct 16, 2026
Merged

almasumdev merged 1 commit into
almasumdev:mainfrom
cdeil:sparse-merge

Conversation

@cdeil

@cdeil cdeil commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Problem. When a sheet is parsed, the cells covered by each <mergeCell>
are cleared by visiting every position of the rectangle. The rectangle comes
from the file, so a 2.4 KB workbook with one cell and A1:ALL10000 costs ten
million iterations, and a single A1:XFD1048576 around one cell took about
three minutes before the first cell could be read; distinct refs multiply
that. Inherited from the original package.

Fix. The walk visits the rows and cells the sheet actually stores inside
the range, choosing per dimension whichever is smaller: the range's width or
the stored count. Keys are collected before mutation. The covered-border
behaviour from #3 is unchanged: a covered cell keeps its style and loses its
value.

Validation. test/reader_test.dart, "Merged Range Parsing": a full-grid
merge around one cell (effectively hangs before, sub-second after) and a
value/style check on covered cells. empty_merged_border_test and the rest of
the suite pass. ALL10000 goes from ~100 ms to 2 ms.

🤖 Generated with Claude Code

Clearing the covered cells of a <mergeCell> visited every position in
the rectangle, so a 2 KB workbook merging A1:ALL10000 around a single
cell cost ten million iterations, and a full-grid merge about three
minutes, before the first cell could be read. The walk now visits the
rows and cells the sheet actually stores inside the range (whichever of
range width or stored count is smaller), keeping the covered-border
behaviour: a covered styled cell keeps its style and loses its value.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@almasumdev
almasumdev merged commit 2e5a936 into almasumdev:main Oct 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants