aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-03-18 10:27:37 +0000
committerPJ Fanning <fanningpj@apache.org>2023-03-18 10:27:37 +0000
commit6e244845e5c55ea9a44a2532a3d3974f90e8e32b (patch)
tree402ae7acb12d007d8eca48767a4628bca7f89b51
parentef82364bde0a434894391d68286c018b261e44ce (diff)
downloadpoi-6e244845e5c55ea9a44a2532a3d3974f90e8e32b.tar.gz
poi-6e244845e5c55ea9a44a2532a3d3974f90e8e32b.zip
[bug-66532] more performant way to iterate over codepoints.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1908479 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java2
-rw-r--r--poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java18
2 files changed, 11 insertions, 9 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java b/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java
index b877f1db56..a936646fe3 100644
--- a/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java
+++ b/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java
@@ -166,7 +166,7 @@ public class CellElapsedFormatter extends CellFormatter {
return SEC__FACTOR / Math.pow(10, len);
default:
throw new IllegalArgumentException(
- "Uknown elapsed time spec: " + type);
+ "Unknown elapsed time spec: " + type);
}
}
diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java b/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
index 9ecc5ce53d..e87343d9f2 100644
--- a/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
+++ b/poi/src/main/java/org/apache/poi/ss/format/CellFormatPart.java
@@ -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('\'');
}