Skip to content

Commit 72b3b06

Browse files
committed
use a more efficient way of iteration
1 parent c03a8dd commit 72b3b06

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/main/java/org/htmlunit/html/serializer/HtmlSerializerInnerOuterText.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ public void append(final String content, final Mode mode) {
387387
}
388388

389389
length--;
390-
int i = -1;
391-
for (char c : content.toCharArray()) {
392-
i++;
390+
final int contentLenght = content.length();
391+
for (int i = 0; i < contentLenght; i++) {
392+
char c = content.charAt(i);
393393

394394
// handle \r
395395
if (c == '\r') {

src/main/java/org/htmlunit/html/serializer/HtmlSerializerNormalizedText.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,10 @@ public void append(final String content, final Mode mode) {
638638
}
639639

640640
boolean crFound = false;
641-
for (final char c : text.toCharArray()) {
641+
final int textLenght = text.length();
642+
for (int i = 0; i < textLenght; i++) {
643+
final char c = text.charAt(i);
644+
642645
if (mode == Mode.NORMALIZE) {
643646
if (isSpace(c)) {
644647
switch (state_) {

src/main/java/org/htmlunit/html/serializer/HtmlSerializerVisibleText.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,9 @@ public void append(final String content, final Mode mode) {
812812
}
813813

814814
length--;
815-
int i = -1;
816-
for (char c : content.toCharArray()) {
817-
i++;
815+
final int contentLenght = content.length();
816+
for (int i = 0; i < contentLenght; i++) {
817+
char c = content.charAt(i);
818818

819819
// handle \r
820820
if (c == '\r') {

0 commit comments

Comments
 (0)