Skip to content
Permalink
Browse files
8273684: Replace usages of java.util.Stack with ArrayDeque
Reviewed-by: cjplummer, serb
  • Loading branch information
turbanoff authored and mrserb committed Sep 22, 2021
1 parent a72c8aa commit cbe57e860487d1a31a092ec326dc64bf5599a00e
Showing 4 changed files with 14 additions and 15 deletions.
@@ -31,12 +31,12 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

import javax.sound.midi.Instrument;
import javax.sound.midi.Patch;
@@ -305,7 +305,7 @@ private boolean readCdlChunk(RIFFReader riff) throws IOException {
DLSID uuid;
long x;
long y;
Stack<Long> stack = new Stack<>();
ArrayDeque<Long> stack = new ArrayDeque<>();

while (riff.available() != 0) {
int opcode = riff.readUnsignedShort();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -2708,15 +2708,14 @@ private void adjustEndElement() {
}

private Element[] getPathTo(int offset) {
Stack<Element> elements = new Stack<Element>();
ArrayList<Element> elements = new ArrayList<Element>();
Element e = getDefaultRootElement();
int index;
while (!e.isLeaf()) {
elements.push(e);
elements.add(e);
e = e.getElement(e.getElementIndex(offset));
}
Element[] retValue = new Element[elements.size()];
elements.copyInto(retValue);
Element[] retValue = elements.toArray(new Element[0]);
return retValue;
}

@@ -33,14 +33,14 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -985,7 +985,7 @@ public void doit(Tokens t) {
Iterator i = agent.getTypeDataBase().getTypes();
// Make sure the types are emitted in an order than can be read back in
HashSet<String> emitted = new HashSet<>();
Stack<Type> pending = new Stack<>();
ArrayDeque<Type> pending = new ArrayDeque<>();
while (i.hasNext()) {
Type n = (Type)i.next();
if (emitted.contains(n.getName())) {
@@ -996,7 +996,7 @@ public void doit(Tokens t) {
pending.push(n);
n = n.getSuperclass();
}
while (!pending.empty()) {
while (!pending.isEmpty()) {
n = (Type)pending.pop();
dumpType(n);
emitted.add(n.getName());
@@ -1381,7 +1381,7 @@ public void doit(Tokens t) {
Iterator i = agent.getTypeDataBase().getTypes();
// Make sure the types are emitted in an order than can be read back in
HashSet<String> emitted = new HashSet<>();
Stack<Type> pending = new Stack<>();
ArrayDeque<Type> pending = new ArrayDeque<>();
while (i.hasNext()) {
Type n = (Type)i.next();
if (emitted.contains(n.getName())) {
@@ -1392,7 +1392,7 @@ public void doit(Tokens t) {
pending.push(n);
n = n.getSuperclass();
}
while (!pending.empty()) {
while (!pending.isEmpty()) {
n = (Type)pending.pop();
dumpType(n);
emitted.add(n.getName());
@@ -214,23 +214,23 @@ public synchronized void paintComponent(Graphics g) {
((Graphics2D) g).setStroke(stroke);
}

Stack<AnnoX> drawStack = new Stack<>();
ArrayDeque<AnnoX> drawStack = new ArrayDeque<>();

layoutAnnotations(va, g, curTextX, startAddr, lineHeight);

for (Iterator<Annotation> iter = visibleAnnotations.iterator(); iter.hasNext(); ) {
Annotation anno = iter.next();
Interval interval = anno.getInterval();

if (!drawStack.empty()) {
if (!drawStack.isEmpty()) {
// See whether we can pop any items off the stack
boolean shouldContinue = true;
do {
AnnoX annoX = (AnnoX) drawStack.peek();
if (annoX.highBound.lessThanOrEqual((Address) interval.getLowEndpoint())) {
curLineX = annoX.lineX;
drawStack.pop();
shouldContinue = !drawStack.empty();
shouldContinue = !drawStack.isEmpty();
} else {
shouldContinue = false;
}

1 comment on commit cbe57e8

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on cbe57e8 Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.