From 2469b89ee62f1d8647d0e2a445f81ce347ced3f5 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 3 Feb 2024 21:06:38 +0000 Subject: [PATCH] [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 --- .../java/org/apache/poi/util/CodepointsUtil.java | 15 ++++++++++++--- 1 file 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 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())); + } + }; } /** -- 2.39.5