You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2023/03/18 10:27:37 UTC

svn commit: r1908479 - in /poi/trunk/poi/src/main/java/org/apache/poi/ss/format: CellElapsedFormatter.java CellFormatPart.java

Author: fanningpj
Date: Sat Mar 18 10:27:37 2023
New Revision: 1908479

URL: http://svn.apache.org/viewvc?rev=1908479&view=rev
Log:
[bug-66532] more performant way to iterate over codepoints.

Modified:
    poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java
    poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java?rev=1908479&r1=1908478&r2=1908479&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java Sat Mar 18 10:27:37 2023
@@ -166,7 +166,7 @@ public class CellElapsedFormatter extend
             return SEC__FACTOR / Math.pow(10, len);
         default:
             throw new IllegalArgumentException(
-                    "Uknown elapsed time spec: " + type);
+                    "Unknown elapsed time spec: " + type);
         }
     }
 

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java?rev=1908479&r1=1908478&r2=1908479&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java Sat Mar 18 10:27:37 2023
@@ -342,9 +342,6 @@ public class CellFormatPart {
             Iterator<String> codePoints = CodepointsUtil.iteratorFor(repl);
             if (codePoints.hasNext()) {
                 String c1 = codePoints.next();
-                String c2 = null;
-                if (codePoints.hasNext())
-                    c2 = codePoints.next().toLowerCase(Locale.ROOT);
 
                 switch (c1) {
                 case "@":
@@ -368,6 +365,9 @@ public class CellFormatPart {
                     seenZero = true;
                     break;
                 case "[":
+                    String c2 = null;
+                    if (codePoints.hasNext())
+                        c2 = codePoints.next().toLowerCase(Locale.ROOT);
                     if ("h".equals(c2) || "m".equals(c2) || "s".equals(c2)) {
                         return CellFormatType.ELAPSED;
                     }
@@ -407,19 +407,21 @@ public class CellFormatPart {
      */
     static String quoteSpecial(String repl, CellFormatType type) {
         StringBuilder sb = new StringBuilder();
-        Iterator<String> codePoints = CodepointsUtil.iteratorFor(repl);
+        PrimitiveIterator.OfInt codePoints = CodepointsUtil.primitiveIterator(repl);
 
+        int codepoint;
         while (codePoints.hasNext()) {
-            String ch = codePoints.next();
-            if ("'".equals(ch) && type.isSpecial('\'')) {
+            codepoint = codePoints.nextInt();
+            if (codepoint == '\'' && type.isSpecial('\'')) {
                 sb.append('\u0000');
                 continue;
             }
 
-            boolean special = type.isSpecial(ch.charAt(0));
+            char[] chars = Character.toChars(codepoint);
+            boolean special = type.isSpecial(chars[0]);
             if (special)
                 sb.append('\'');
-            sb.append(ch);
+            sb.append(chars);
             if (special)
                 sb.append('\'');
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org