aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-02-03 21:06:38 +0000
committerPJ Fanning <fanningpj@apache.org>2024-02-03 21:06:38 +0000
commit2469b89ee62f1d8647d0e2a445f81ce347ced3f5 (patch)
tree87bc41de64715b627866c34e2b52a252787f915a
parente45579801975c995bd846f41f9318cc11b56ffb3 (diff)
downloadpoi-2469b89ee62f1d8647d0e2a445f81ce347ced3f5.tar.gz
poi-2469b89ee62f1d8647d0e2a445f81ce347ced3f5.zip
[github-582] improve performance CodepointsUtil.iteratorFor. Thanks to Jason Mirra. This closes #582
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1915572 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/main/java/org/apache/poi/util/CodepointsUtil.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/poi/src/main/java/org/apache/poi/util/CodepointsUtil.java b/poi/src/main/java/org/apache/poi/util/CodepointsUtil.java
index b74cf8a88c..732af2e3ff 100644
--- a/poi/src/main/java/org/apache/poi/util/CodepointsUtil.java
+++ b/poi/src/main/java/org/apache/poi/util/CodepointsUtil.java
@@ -29,9 +29,18 @@ public class CodepointsUtil {
* @see #primitiveIterator(String) a more performant iterator
*/
public static Iterator<String> iteratorFor(String text) {
- return text.codePoints()
- .mapToObj(codePoint -> new String(Character.toChars(codePoint)))
- .iterator();
+ final PrimitiveIterator.OfInt iter = primitiveIterator(text);
+ return new Iterator<String>() {
+ @Override
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ @Override
+ public String next() {
+ return new String(Character.toChars(iter.nextInt()));
+ }
+ };
}
/**