]> source.dussan.org Git - poi.git/commitdiff
[github-582] improve performance CodepointsUtil.iteratorFor. Thanks to Jason Mirra...
authorPJ Fanning <fanningpj@apache.org>
Sat, 3 Feb 2024 21:06:38 +0000 (21:06 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 3 Feb 2024 21:06:38 +0000 (21:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1915572 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/util/CodepointsUtil.java

index b74cf8a88cfe9595f42a80fb77dd5dfda03ff7fb..732af2e3ff545367c62415c7ee8db0910658aa50 100644 (file)
@@ -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()));
+            }
+        };
     }
 
     /**