This closes #2191, add Rows.IterateColumns to stream cells without []string allocation#2330
Open
artur-chopikian wants to merge 1 commit into
Open
This closes #2191, add Rows.IterateColumns to stream cells without []string allocation#2330artur-chopikian wants to merge 1 commit into
artur-chopikian wants to merge 1 commit into
Conversation
…out []string allocation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2330 +/- ##
=======================================
Coverage 99.60% 99.60%
=======================================
Files 32 32
Lines 26794 26807 +13
=======================================
+ Hits 26688 26701 +13
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.
Description
Adds a new
Rows.IterateColumnsmethod that streams each non-empty cell of the current row through a user-supplied callbackfunc(colIndex int, cellValue string), instead ofreturning a
[]stringlikeRows.Columnsdoes.Internally, the SAX parse loop in
Columnsis extracted into a privateiteratehelper that both methods share.rowXMLIteratorgains ayieldfield; when set,rowXMLHandlercalls it per cell and skips the
append(appendSpace(...), val)accumulation. When unset, the original code path runs verbatim —Columnskeeps its existing behavior and pays onlya single nil check per cell.
Related Issue
Closes: #2191.
Motivation and Context
Rows.Columnsallocates and grows a[]stringfor every row, and fills middle gaps between non-empty cells with"". On wide or sparse rows this is a significant amount of workthe caller doesn't actually need — most callers immediately iterate the slice and never retain it.
IterateColumnslets callers consume cells directly, eliminating the sliceallocation, the
appendregrowth chain, and the gap-filling loop, while preserving the existingColumnsAPI and performance.Usage:
How Has This Been Tested
Added
TestIterateColumnsinrows_test.gocovering:Columns: iteratestest/Book1.xlsxSheet2 with both APIs and compares the resulting rows after trimming trailing empties.C1,E1,A3,B3,E3and reconstructs the cell map from(rowIdx, colIndex)pairs — verifies column indices reflect actualpositions, not emission order.
nilis a safe no-op and returns no error.Options{RawCellValue: true}yields the unformatted raw value throughIterateColumnsexactly as it doesthrough
Columns.Ran the existing
TestRows,TestGetRows, andTestRowsIteratorto confirm no regression on the sharediteratepath.Types of changes
Checklist