]> source.dussan.org Git - poi.git/commitdiff
[github-405] more performant codepoint util code. Thanks to StanBertrand. This closes...
authorPJ Fanning <fanningpj@apache.org>
Mon, 12 Dec 2022 14:59:35 +0000 (14:59 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 12 Dec 2022 14:59:35 +0000 (14:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905932 13f79535-47bb-0310-9956-ffa450edef68

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

index 107e37416eaf18b4efbc5a7d59da1f74a66c7dfb..9f2d01780cbc99b9beaaf8308bd1b3e617ed7277 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Iterator;
 public class CodepointsUtil {
     public static Iterator<String> iteratorFor(String text) {
         return text.codePoints()
-                .mapToObj(codePoint -> new StringBuilder().appendCodePoint(codePoint).toString())
+                .mapToObj(codePoint -> new String(Character.toChars(codePoint)))
                 .iterator();
     }
 }
\ No newline at end of file
index 35a05af33e309ca279ffb5600e4ab082be0a9c7e..3610535c95f4a13a24648a7c997261a7043b3128 100644 (file)
@@ -35,7 +35,6 @@ class TestCodepointsUtil {
     void testIterator() {
         final String unicodeSurrogates = "\uD835\uDF4A\uD835\uDF4B\uD835\uDF4C\uD835\uDF4D\uD835\uDF4E"
                 + "abcdef123456";
-        Iterator<String> sci = CodepointsUtil.iteratorFor(unicodeSurrogates);
         List<String> codePoints = new ArrayList<>();
         CodepointsUtil.iteratorFor(unicodeSurrogates).forEachRemaining(codePoints::add);
         assertEquals(17, codePoints.size());