softvisionfd opened a new pull request, #1358:
URL: https://github.com/apache/poi/pull/1358

   `XWPFHeaderFooterPolicy(XWPFDocument, CTSectPr)` iterates the header and 
footer references with `sizeOfHeaderReferenceArray()` / 
`getHeaderReferenceArray(i)`. XmlBeans counts or walks the element's children 
on each of these calls, so opening a document is quadratic in the number of 
references of a section. A crafted section with 40,000 `w:headerReference` 
elements (11 KB .docx) takes 19 s to open with 5.5.1; with this change 0.1 s.
   
   The change iterates over `getHeaderReferenceArray()` / 
`getFooterReferenceArray()`, which collect the children in one pass. The order 
is unchanged, so the last reference of a type still wins (checked with all 
header/footer types plus a duplicate default reference: identical result before 
and after).
   
   Test: `TestXWPFHeaderFooterPolicy#testLastReferenceOfATypeWins` pins the 
order in which the references are read (a second default reference wins over 
the first). It passes before and after the change; a timing assertion would be 
flaky, so the speed-up itself is not asserted.
   
   Tested: the change was compiled against trunk and measured with the patched 
class on 5.5.1; the new test passes with and without the change. I did not run 
the full Gradle build locally.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to