Restore sorted cell iteration order with lazy cache#1759
Merged
tonyqus merged 1 commit intoMar 24, 2026
Merged
Conversation
PR nissl-lab#1753 replaced SortedDictionary with Dictionary in XSSFRow for O(1) insert/lookup, but GetEnumerator() and Cells no longer returned cells in ascending column order — a breaking change for existing consumers. Add a lazily-built sorted cell cache (List<ICell>) that is populated on first read and invalidated on mutation (add/remove/rebuild). This preserves the Dictionary performance win while restoring the sorted iteration contract. Applied consistently to XSSFRow, HSSFRow, and SXSSFRow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
Member
|
LGTM |
This was referenced Apr 6, 2026
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.
Summary
SortedDictionarywithDictionaryinXSSFRow,GetEnumerator()andCellsno longer returned cells in ascending column order — a breaking change for existing consumers whoforeachover rowsList<ICell>) that is populated on first read and invalidated on mutation (add/remove/rebuild)DictionaryO(1) insert/lookup performance win while restoring the sorted iteration contractXSSFRow,HSSFRow, andSXSSFRowContext
Raised by @tonyqus in #1742 (comment) — the
SortedDictionary→Dictionarychange in #1753 means cells returned fromGetEnumeratorare no longer sorted by column index, which could break existing NPOI-based logic that assumes sorted iteration.Design
null-ed) on any cell mutation —CreateCell,RemoveCell,RebuildCellsSortedDictionarybehavior that would throwInvalidOperationExceptionon concurrent modificationXSSFRow.OnDocumentWrite()also reuses the cache instead of re-sortingTest plan
TestCellIterationOrderWithSparseColumnspasses (net8.0 + net472)🤖 Generated with Claude Code