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

GH-2797: Lazy init for ValidationState hash maps #2798

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -28,6 +28,8 @@
/**
* Implementation of the ValidationContext interface. Used to establish an
* environment for simple type validation.
* <p>
* This class is not thread-safe.
*
* {@literal @xerces.internal}
*
Expand All @@ -50,9 +52,10 @@ public class ValidationState implements ValidationContext {
private SymbolTable fSymbolTable = null;
private Locale fLocale = null;

//REVISIT: Should replace with a lighter structure.
private final HashMap fIdTable = new HashMap();
private final HashMap fIdRefTable = new HashMap();
// REVISIT: Should replace with a lighter structure.
// These tables are initialized only on demand to avoid unneeded allocations.
private HashMap fIdTable = null;
private HashMap fIdRefTable = null;
private final static Object fNullValue = new Object();

//
Expand Down Expand Up @@ -91,11 +94,12 @@ public void setSymbolTable(SymbolTable sTable) {
* otherwise return the first IDREF value without a matching ID value.
*/
public String checkIDRefID () {
if (fIdRefTable == null) return null;
Iterator iter = fIdRefTable.keySet().iterator();
String key;
while (iter.hasNext()) {
key = (String) iter.next();
if (!fIdTable.containsKey(key)) {
if (fIdTable == null || !fIdTable.containsKey(key)) {
return key;
}
}
Expand All @@ -106,8 +110,8 @@ public void reset () {
fExtraChecking = true;
fFacetChecking = true;
fNamespaces = true;
fIdTable.clear();
fIdRefTable.clear();
fIdTable = null;
fIdRefTable = null;
fEntityState = null;
fNamespaceContext = null;
fSymbolTable = null;
Expand All @@ -120,8 +124,8 @@ public void reset () {
* the two tables.
*/
public void resetIDTables() {
fIdTable.clear();
fIdRefTable.clear();
fIdTable = null;
fIdRefTable = null;
}

//
Expand Down Expand Up @@ -169,16 +173,25 @@ public boolean isEntityUnparsed (String name) {
// id
@Override
public boolean isIdDeclared(String name) {
if (fIdTable == null) {
return false;
}
return fIdTable.containsKey(name);
}
@Override
public void addId(String name) {
if (fIdTable == null) {
fIdTable = new HashMap();
}
fIdTable.put(name, fNullValue);
}

// idref
@Override
public void addIdRef(String name) {
if (fIdRefTable == null) {
fIdRefTable = new HashMap();
}
fIdRefTable.put(name, fNullValue);
}
// get symbols
Expand Down