pjfanning commented on code in PR #1525:
URL: https://github.com/apache/poi/pull/1525#discussion_r4454751016
##########
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java:
##########
@@ -63,17 +71,24 @@ public final class PackagePartCollection implements
Serializable {
*/
public PackagePart put(final PackagePartName partName, final PackagePart
part) {
final String ppName = partName.getName();
- final StringBuilder concatSeg = new StringBuilder();
- // split at slash, but keep leading slash
- final String delim =
"(?=["+PackagingURIHelper.FORWARD_SLASH_STRING+"])";
- for (String seg : ppName.split(delim)) {
- concatSeg.append(seg);
- if (registerPartNameStr.contains(concatSeg.toString())) {
+ // check the name up to each slash (but the leading one) and the whole
name -
+ // only build the prefixes which are as long as a registered name, as
building
+ // every prefix takes quadratic time for deeply nested names
+ int end = ppName.indexOf(PackagingURIHelper.FORWARD_SLASH_CHAR, 1);
+ while (true) {
+ final int len = (end < 0) ? ppName.length() : end;
+ if (registerPartNameLengths.containsKey(len)
Review Comment:
if you go for a BitSet, use the SparseBitSet lib that we have as a POI
dependency already
--
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]