Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a ArrayDeque #5

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -35,7 +37,7 @@ public class PrettyPrintXMLWriter

private PrintWriter writer;

private LinkedList<String> elementStack = new LinkedList<String>();
private final Deque<String> elementStack = new ArrayDeque<>();

private boolean tagInProgress;

Expand Down Expand Up @@ -307,11 +309,6 @@ public void endElement()
{
finishTag();

// see issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51
// Rationale: replaced 1 write() with string concatenations with 3 write()
// (this avoids the string concatenation optimization bug detected in Java 7)
// TODO: change the below code to a more efficient expression when the library
// be ready to target Java 8.
write( "</" );
write( elementStack.removeLast() );
write( ">" );
Expand Down Expand Up @@ -518,7 +515,7 @@ protected String getDocType()
/**
* @return the current elementStack;
*/
protected LinkedList<String> getElementStack()
protected Deque<String> getElementStack()
{
return elementStack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.NoSuchElementException;

Expand All @@ -28,6 +29,7 @@
import org.codehaus.plexus.util.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -178,6 +180,7 @@ public void testendElementAlreadyClosed()
*
* @throws java.io.IOException if an I/O error occurs
*/
@Disabled( "This test is only relevant on JDK 1.7, which is not supported anymore" )
@Test
public void testIssue51DetectJava7ConcatenationBug()
throws IOException
Expand All @@ -191,7 +194,7 @@ public void testIssue51DetectJava7ConcatenationBug()

int iterations = 20000;

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