fix: compact sparse worksheet rows in linear time#2334
Closed
rootsec1 wants to merge 1 commit into
Closed
Conversation
Contributor
Author
|
Closing to reopen from a neutral branch name. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2334 +/- ##
==========================================
- Coverage 99.60% 99.60% -0.01%
==========================================
Files 32 32
Lines 26866 26864 -2
==========================================
- Hits 26760 26758 -2
Misses 55 55
Partials 51 51
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This changes
trimRowto compact worksheet rows in place with a write index instead of deleting each empty row from the middle of the backing slice.The observable behavior is the same: empty rows are removed, cells inside retained rows are still trimmed, and rows with attributes such as
hiddenare preserved.Why
Some valid XLSX files have a very sparse worksheet row list, for example when the sheet dimension reaches Excel's maximum row because of a single far-down cell. In that case, many intermediate rows can be empty.
The previous implementation used:
inside the scan loop. When many empty rows are present, that repeatedly shifts the remaining slice contents and can make saving sparse worksheets take quadratic time.
How this fixes it
The new implementation performs one forward pass:
This avoids repeated large memory moves while preserving row order and the existing trim semantics.
Tests
Added synthetic coverage only; no external or private workbook fixtures are included.
TestTrimRowCompactsSparseRowsverifies blank rows and blank cells are removed while rows with attributes are retained.BenchmarkTrimRowSparseRowscovers a sparse worksheet shape with 50,000 row entries and only a small number of retained rows.Local verification: