Author: lehmi Date: Tue May 21 18:06:02 2024 New Revision: 1917862 URL: http://svn.apache.org/viewvc?rev=1917862&view=rev Log: PDFBOX-5823: simplify pattern matching to optimize memory consumption based on a proposal by Jonathan Prates
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java?rev=1917862&r1=1917861&r2=1917862&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java (original) +++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java Tue May 21 18:06:02 2024 @@ -1623,7 +1623,11 @@ abstract class PDAbstractContentStream i for (String word : words) { - if (StringUtil.PATTERN_SPACE.matcher(word).matches()) + if (word == null) + { + continue; + } + if (word.length() == 1 && StringUtil.PREDICATE_SPACE.test(word)) { out.write(font.encode(word)); } Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java?rev=1917862&r1=1917861&r2=1917862&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java (original) +++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java Tue May 21 18:06:02 2024 @@ -17,11 +17,13 @@ package org.apache.pdfbox.util; import java.util.Arrays; +import java.util.function.Predicate; import java.util.regex.Pattern; public final class StringUtil { public static final Pattern PATTERN_SPACE = Pattern.compile("\\s"); + public static final Predicate<String> PREDICATE_SPACE = PATTERN_SPACE.asPredicate(); public static String[] splitOnSpace(String s) {