Skip to content

Commit

Permalink
8295323: Unnecessary HashTable usage in StyleSheet
Browse files Browse the repository at this point in the history
Reviewed-by: aivanov, prr
  • Loading branch information
Andrey Turbanov committed Oct 27, 2022
1 parent 2157145 commit 907d583
Showing 1 changed file with 16 additions and 18 deletions.
Expand Up @@ -1359,12 +1359,11 @@ private synchronized void getStyles(SelectorMapping parentMapping,
Vector<SelectorMapping> styles,
String[] tags, String[] ids, String[] classes,
int index, int numElements,
Hashtable<SelectorMapping, SelectorMapping> alreadyChecked) {
// Avoid desending the same mapping twice.
if (alreadyChecked.contains(parentMapping)) {
HashSet<SelectorMapping> alreadyChecked) {
// Avoid descending the same mapping twice.
if (!alreadyChecked.add(parentMapping)) {
return;
}
alreadyChecked.put(parentMapping, parentMapping);
Style style = parentMapping.getStyle();
if (style != null) {
addSortedStyle(parentMapping, styles);
Expand Down Expand Up @@ -1422,8 +1421,7 @@ private synchronized Style createResolvedStyle(String selector,
SearchBuffer sb = SearchBuffer.obtainSearchBuffer();
@SuppressWarnings("unchecked")
Vector<SelectorMapping> tempVector = sb.getVector();
@SuppressWarnings("unchecked")
Hashtable<SelectorMapping, SelectorMapping> tempHashtable = sb.getHashtable();
HashSet<SelectorMapping> alreadyChecked = sb.getHashSet();
// Determine all the Styles that are appropriate, placing them
// in tempVector
try {
Expand All @@ -1434,21 +1432,21 @@ private synchronized Style createResolvedStyle(String selector,
tagString, false);
if (childMapping != null) {
getStyles(childMapping, tempVector, tags, ids, classes, 1,
numElements, tempHashtable);
numElements, alreadyChecked);
}
if (classes[0] != null) {
String className = classes[0];
childMapping = mapping.getChildSelectorMapping(
tagString + "." + className, false);
if (childMapping != null) {
getStyles(childMapping, tempVector, tags, ids, classes, 1,
numElements, tempHashtable);
numElements, alreadyChecked);
}
childMapping = mapping.getChildSelectorMapping(
"." + className, false);
if (childMapping != null) {
getStyles(childMapping, tempVector, tags, ids, classes,
1, numElements, tempHashtable);
1, numElements, alreadyChecked);
}
}
if (ids[0] != null) {
Expand All @@ -1457,13 +1455,13 @@ private synchronized Style createResolvedStyle(String selector,
tagString + "#" + idName, false);
if (childMapping != null) {
getStyles(childMapping, tempVector, tags, ids, classes,
1, numElements, tempHashtable);
1, numElements, alreadyChecked);
}
childMapping = mapping.getChildSelectorMapping(
"#" + idName, false);
if (childMapping != null) {
getStyles(childMapping, tempVector, tags, ids, classes,
1, numElements, tempHashtable);
1, numElements, alreadyChecked);
}
}
// Create a new Style that will delegate to all the matching
Expand Down Expand Up @@ -1754,7 +1752,7 @@ private static class SearchBuffer {
// A set of temporary variables that can be used in whatever way.
Vector vector = null;
StringBuffer stringBuffer = null;
Hashtable hashtable = null;
HashSet<SelectorMapping> hashSet = null;

/**
* Returns an instance of SearchBuffer. Be sure and issue
Expand Down Expand Up @@ -1797,11 +1795,11 @@ Vector getVector() {
return vector;
}

Hashtable getHashtable() {
if (hashtable == null) {
hashtable = new Hashtable();
HashSet<SelectorMapping> getHashSet() {
if (hashSet == null) {
hashSet = new HashSet<>();
}
return hashtable;
return hashSet;
}

void empty() {
Expand All @@ -1811,8 +1809,8 @@ void empty() {
if (vector != null) {
vector.removeAllElements();
}
if (hashtable != null) {
hashtable.clear();
if (hashSet != null) {
hashSet.clear();
}
}
}
Expand Down

1 comment on commit 907d583

@openjdk-notifier
Copy link

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.