Skip to content

Commit a20dcd8

Browse files
Andrey Turbanovpull[bot]
authored andcommitted
8295323: Unnecessary HashTable usage in StyleSheet
Reviewed-by: aivanov, prr
1 parent 069a07d commit a20dcd8

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,12 +1359,11 @@ private synchronized void getStyles(SelectorMapping parentMapping,
13591359
Vector<SelectorMapping> styles,
13601360
String[] tags, String[] ids, String[] classes,
13611361
int index, int numElements,
1362-
Hashtable<SelectorMapping, SelectorMapping> alreadyChecked) {
1363-
// Avoid desending the same mapping twice.
1364-
if (alreadyChecked.contains(parentMapping)) {
1362+
HashSet<SelectorMapping> alreadyChecked) {
1363+
// Avoid descending the same mapping twice.
1364+
if (!alreadyChecked.add(parentMapping)) {
13651365
return;
13661366
}
1367-
alreadyChecked.put(parentMapping, parentMapping);
13681367
Style style = parentMapping.getStyle();
13691368
if (style != null) {
13701369
addSortedStyle(parentMapping, styles);
@@ -1422,8 +1421,7 @@ private synchronized Style createResolvedStyle(String selector,
14221421
SearchBuffer sb = SearchBuffer.obtainSearchBuffer();
14231422
@SuppressWarnings("unchecked")
14241423
Vector<SelectorMapping> tempVector = sb.getVector();
1425-
@SuppressWarnings("unchecked")
1426-
Hashtable<SelectorMapping, SelectorMapping> tempHashtable = sb.getHashtable();
1424+
HashSet<SelectorMapping> alreadyChecked = sb.getHashSet();
14271425
// Determine all the Styles that are appropriate, placing them
14281426
// in tempVector
14291427
try {
@@ -1434,21 +1432,21 @@ private synchronized Style createResolvedStyle(String selector,
14341432
tagString, false);
14351433
if (childMapping != null) {
14361434
getStyles(childMapping, tempVector, tags, ids, classes, 1,
1437-
numElements, tempHashtable);
1435+
numElements, alreadyChecked);
14381436
}
14391437
if (classes[0] != null) {
14401438
String className = classes[0];
14411439
childMapping = mapping.getChildSelectorMapping(
14421440
tagString + "." + className, false);
14431441
if (childMapping != null) {
14441442
getStyles(childMapping, tempVector, tags, ids, classes, 1,
1445-
numElements, tempHashtable);
1443+
numElements, alreadyChecked);
14461444
}
14471445
childMapping = mapping.getChildSelectorMapping(
14481446
"." + className, false);
14491447
if (childMapping != null) {
14501448
getStyles(childMapping, tempVector, tags, ids, classes,
1451-
1, numElements, tempHashtable);
1449+
1, numElements, alreadyChecked);
14521450
}
14531451
}
14541452
if (ids[0] != null) {
@@ -1457,13 +1455,13 @@ private synchronized Style createResolvedStyle(String selector,
14571455
tagString + "#" + idName, false);
14581456
if (childMapping != null) {
14591457
getStyles(childMapping, tempVector, tags, ids, classes,
1460-
1, numElements, tempHashtable);
1458+
1, numElements, alreadyChecked);
14611459
}
14621460
childMapping = mapping.getChildSelectorMapping(
14631461
"#" + idName, false);
14641462
if (childMapping != null) {
14651463
getStyles(childMapping, tempVector, tags, ids, classes,
1466-
1, numElements, tempHashtable);
1464+
1, numElements, alreadyChecked);
14671465
}
14681466
}
14691467
// Create a new Style that will delegate to all the matching
@@ -1754,7 +1752,7 @@ private static class SearchBuffer {
17541752
// A set of temporary variables that can be used in whatever way.
17551753
Vector vector = null;
17561754
StringBuffer stringBuffer = null;
1757-
Hashtable hashtable = null;
1755+
HashSet<SelectorMapping> hashSet = null;
17581756

17591757
/**
17601758
* Returns an instance of SearchBuffer. Be sure and issue
@@ -1797,11 +1795,11 @@ Vector getVector() {
17971795
return vector;
17981796
}
17991797

1800-
Hashtable getHashtable() {
1801-
if (hashtable == null) {
1802-
hashtable = new Hashtable();
1798+
HashSet<SelectorMapping> getHashSet() {
1799+
if (hashSet == null) {
1800+
hashSet = new HashSet<>();
18031801
}
1804-
return hashtable;
1802+
return hashSet;
18051803
}
18061804

18071805
void empty() {
@@ -1811,8 +1809,8 @@ void empty() {
18111809
if (vector != null) {
18121810
vector.removeAllElements();
18131811
}
1814-
if (hashtable != null) {
1815-
hashtable.clear();
1812+
if (hashSet != null) {
1813+
hashSet.clear();
18161814
}
18171815
}
18181816
}

0 commit comments

Comments
 (0)