From: PJ Fanning Date: Sat, 3 Feb 2024 21:06:38 +0000 (+0000) Subject: [github-582] improve performance CodepointsUtil.iteratorFor. Thanks to Jason Mirra... X-Git-Tag: REL_5_3_0~111 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2469b89ee62f1d8647d0e2a445f81ce347ced3f5;p=poi.git [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 --- 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 iteratorFor(String text) { - return text.codePoints() - .mapToObj(codePoint -> new String(Character.toChars(codePoint))) - .iterator(); + final PrimitiveIterator.OfInt iter = primitiveIterator(text); + return new Iterator() { + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public String next() { + return new String(Character.toChars(iter.nextInt())); + } + }; } /**