Skip to content

Commit a48289a

Browse files
committed
8329761: Remove unused KeyBuilder and unusedSets from StyleContext
Reviewed-by: serb, tr
1 parent 8907eda commit a48289a

File tree

1 file changed

+6
-156
lines changed

1 file changed

+6
-156
lines changed

src/java.desktop/share/classes/javax/swing/text/StyleContext.java

Lines changed: 6 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,6 @@
4444
import java.util.Hashtable;
4545
import java.util.Map;
4646
import java.util.NoSuchElementException;
47-
import java.util.Vector;
4847
import java.util.WeakHashMap;
4948

5049
import javax.swing.SwingUtilities;
@@ -212,10 +211,9 @@ public Font getFont(AttributeSet attr) {
212211
String family = StyleConstants.getFontFamily(attr);
213212
int size = StyleConstants.getFontSize(attr);
214213

215-
/**
216-
* if either superscript or subscript is
217-
* is set, we need to reduce the font size
218-
* by 2.
214+
/*
215+
* If either superscript or subscript is set,
216+
* we need to reduce the font size by 2.
219217
*/
220218
if (StyleConstants.isSuperscript(attr) ||
221219
StyleConstants.isSubscript(attr)) {
@@ -763,7 +761,6 @@ private void readObject(ObjectInputStream s)
763761
throw new InvalidObjectException("Null styles");
764762
}
765763
styles = newStyles;
766-
unusedSets = f.get("unusedSets", 0);
767764
}
768765

769766
// --- variables ---------------------------------------------------
@@ -785,14 +782,6 @@ private void readObject(ObjectInputStream s)
785782
synchronizedMap(new WeakHashMap<SmallAttributeSet, WeakReference<SmallAttributeSet>>());
786783
private transient MutableAttributeSet search = new SimpleAttributeSet();
787784

788-
/**
789-
* Number of immutable sets that are not currently
790-
* being used. This helps indicate when the sets need
791-
* to be cleaned out of the hashtable they are stored
792-
* in.
793-
*/
794-
private int unusedSets;
795-
796785
/**
797786
* The threshold for no longer sharing the set of attributes
798787
* in an immutable table.
@@ -1055,7 +1044,7 @@ public AttributeSet getResolveParent() {
10551044
/**
10561045
* An enumeration of the keys in a SmallAttributeSet.
10571046
*/
1058-
static class KeyEnumeration implements Enumeration<Object> {
1047+
static final class KeyEnumeration implements Enumeration<Object> {
10591048

10601049
KeyEnumeration(Object[] attr) {
10611050
this.attr = attr;
@@ -1093,149 +1082,10 @@ public Object nextElement() {
10931082
int i;
10941083
}
10951084

1096-
/**
1097-
* Sorts the key strings so that they can be very quickly compared
1098-
* in the attribute set searches.
1099-
*/
1100-
static class KeyBuilder {
1101-
1102-
public void initialize(AttributeSet a) {
1103-
if (a instanceof SmallAttributeSet) {
1104-
initialize(((SmallAttributeSet)a).attributes);
1105-
} else {
1106-
keys.removeAllElements();
1107-
data.removeAllElements();
1108-
Enumeration<?> names = a.getAttributeNames();
1109-
while (names.hasMoreElements()) {
1110-
Object name = names.nextElement();
1111-
addAttribute(name, a.getAttribute(name));
1112-
}
1113-
}
1114-
}
1115-
1116-
/**
1117-
* Initialize with a set of already sorted
1118-
* keys (data from an existing SmallAttributeSet).
1119-
*/
1120-
private void initialize(Object[] sorted) {
1121-
keys.removeAllElements();
1122-
data.removeAllElements();
1123-
int n = sorted.length;
1124-
for (int i = 0; i < n; i += 2) {
1125-
keys.addElement(sorted[i]);
1126-
data.addElement(sorted[i+1]);
1127-
}
1128-
}
1129-
1130-
/**
1131-
* Creates a table of sorted key/value entries
1132-
* suitable for creation of an instance of
1133-
* SmallAttributeSet.
1134-
*/
1135-
public Object[] createTable() {
1136-
int n = keys.size();
1137-
Object[] tbl = new Object[2 * n];
1138-
for (int i = 0; i < n; i ++) {
1139-
int offs = 2 * i;
1140-
tbl[offs] = keys.elementAt(i);
1141-
tbl[offs + 1] = data.elementAt(i);
1142-
}
1143-
return tbl;
1144-
}
1145-
1146-
/**
1147-
* The number of key/value pairs contained
1148-
* in the current key being forged.
1149-
*/
1150-
int getCount() {
1151-
return keys.size();
1152-
}
1153-
1154-
/**
1155-
* Adds a key/value to the set.
1156-
*/
1157-
public void addAttribute(Object key, Object value) {
1158-
keys.addElement(key);
1159-
data.addElement(value);
1160-
}
1161-
1162-
/**
1163-
* Adds a set of key/value pairs to the set.
1164-
*/
1165-
public void addAttributes(AttributeSet attr) {
1166-
if (attr instanceof SmallAttributeSet) {
1167-
// avoid searching the keys, they are already interned.
1168-
Object[] tbl = ((SmallAttributeSet)attr).attributes;
1169-
int n = tbl.length;
1170-
for (int i = 0; i < n; i += 2) {
1171-
addAttribute(tbl[i], tbl[i+1]);
1172-
}
1173-
} else {
1174-
Enumeration<?> names = attr.getAttributeNames();
1175-
while (names.hasMoreElements()) {
1176-
Object name = names.nextElement();
1177-
addAttribute(name, attr.getAttribute(name));
1178-
}
1179-
}
1180-
}
1181-
1182-
/**
1183-
* Removes the given name from the set.
1184-
*/
1185-
public void removeAttribute(Object key) {
1186-
int n = keys.size();
1187-
for (int i = 0; i < n; i++) {
1188-
if (keys.elementAt(i).equals(key)) {
1189-
keys.removeElementAt(i);
1190-
data.removeElementAt(i);
1191-
return;
1192-
}
1193-
}
1194-
}
1195-
1196-
/**
1197-
* Removes the set of keys from the set.
1198-
*/
1199-
public void removeAttributes(Enumeration<?> names) {
1200-
while (names.hasMoreElements()) {
1201-
Object name = names.nextElement();
1202-
removeAttribute(name);
1203-
}
1204-
}
1205-
1206-
/**
1207-
* Removes the set of matching attributes from the set.
1208-
*/
1209-
public void removeAttributes(AttributeSet attr) {
1210-
Enumeration<?> names = attr.getAttributeNames();
1211-
while (names.hasMoreElements()) {
1212-
Object name = names.nextElement();
1213-
Object value = attr.getAttribute(name);
1214-
removeSearchAttribute(name, value);
1215-
}
1216-
}
1217-
1218-
private void removeSearchAttribute(Object ikey, Object value) {
1219-
int n = keys.size();
1220-
for (int i = 0; i < n; i++) {
1221-
if (keys.elementAt(i).equals(ikey)) {
1222-
if (data.elementAt(i).equals(value)) {
1223-
keys.removeElementAt(i);
1224-
data.removeElementAt(i);
1225-
}
1226-
return;
1227-
}
1228-
}
1229-
}
1230-
1231-
private Vector<Object> keys = new Vector<Object>();
1232-
private Vector<Object> data = new Vector<Object>();
1233-
}
1234-
12351085
/**
12361086
* key for a font table
12371087
*/
1238-
static class FontKey {
1088+
static final class FontKey {
12391089

12401090
private String family;
12411091
private int style;

0 commit comments

Comments
 (0)