Skip to content

Commit 6a02a98

Browse files
committed
Use a ArrayDeque
1 parent b341280 commit 6a02a98

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.PrintWriter;
2020
import java.io.Writer;
21+
import java.util.ArrayDeque;
22+
import java.util.Deque;
2123
import java.util.LinkedList;
2224
import java.util.regex.Matcher;
2325
import java.util.regex.Pattern;
@@ -35,7 +37,7 @@ public class PrettyPrintXMLWriter
3537

3638
private PrintWriter writer;
3739

38-
private LinkedList<String> elementStack = new LinkedList<String>();
40+
private final Deque<String> elementStack = new ArrayDeque<>();
3941

4042
private boolean tagInProgress;
4143

@@ -307,11 +309,6 @@ public void endElement()
307309
{
308310
finishTag();
309311

310-
// see issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51
311-
// Rationale: replaced 1 write() with string concatenations with 3 write()
312-
// (this avoids the string concatenation optimization bug detected in Java 7)
313-
// TODO: change the below code to a more efficient expression when the library
314-
// be ready to target Java 8.
315312
write( "</" );
316313
write( elementStack.removeLast() );
317314
write( ">" );
@@ -518,7 +515,7 @@ protected String getDocType()
518515
/**
519516
* @return the current elementStack;
520517
*/
521-
protected LinkedList<String> getElementStack()
518+
protected Deque<String> getElementStack()
522519
{
523520
return elementStack;
524521
}

src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.IOException;
2121
import java.io.OutputStreamWriter;
2222
import java.io.StringWriter;
23+
import java.io.Writer;
24+
import java.nio.charset.StandardCharsets;
2325
import java.nio.file.Files;
2426
import java.util.NoSuchElementException;
2527

@@ -191,7 +193,7 @@ public void testIssue51DetectJava7ConcatenationBug()
191193

192194
int iterations = 20000;
193195

194-
try ( OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream( xmlFile.toPath() ), "UTF-8" ) )
196+
try ( Writer osw = Files.newBufferedWriter( xmlFile.toPath(), StandardCharsets.UTF_8 ) )
195197
{
196198
writer = new PrettyPrintXMLWriter( osw );
197199
for ( int i = 0; i < iterations; ++i )

0 commit comments

Comments
 (0)