Skip to content

Commit

Permalink
#216 Cleanup: unused private static arrays in WstxInputData and Strea…
Browse files Browse the repository at this point in the history
…mScanner (#217)
  • Loading branch information
winfriedgerlach authored Nov 22, 2024
1 parent e40a403 commit dd14f34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 139 deletions.
93 changes: 0 additions & 93 deletions src/main/java/com/ctc/wstx/io/WstxInputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,99 +50,6 @@ public class WstxInputData
*/
public final static int MAX_UNICODE_CHAR = 0x10FFFF;

/*
////////////////////////////////////////////////////
// Character validity constants, structs
////////////////////////////////////////////////////
*/

/**
* We will only use validity array for first 256 characters, mostly
* because after those characters it's easier to do fairly simple
* block checks.
*/
private final static int VALID_CHAR_COUNT = 0x100;

// These are the same for both 1.0 and 1.1...
// private final static int FIRST_VALID_FOR_FIRST = 0x0041; // 'A'
// private final static int FIRST_VALID_FOR_REST = 0x002D; // '.'

private final static byte NAME_CHAR_INVALID_B = (byte) 0;
private final static byte NAME_CHAR_ALL_VALID_B = (byte) 1;
private final static byte NAME_CHAR_VALID_NONFIRST_B = (byte) -1;

private final static byte[] sCharValidity = new byte[VALID_CHAR_COUNT];

static {
/* First, since all valid-as-first chars are also valid-as-other chars,
* we'll initialize common chars:
*/
sCharValidity['_'] = NAME_CHAR_ALL_VALID_B;
for (int i = 0, last = ('z' - 'a'); i <= last; ++i) {
sCharValidity['A' + i] = NAME_CHAR_ALL_VALID_B;
sCharValidity['a' + i] = NAME_CHAR_ALL_VALID_B;
}
// not all are fully valid, but
for (int i = 0xC0; i < VALID_CHAR_COUNT; ++i) {
sCharValidity[i] = NAME_CHAR_ALL_VALID_B;
}
// ... now we can 'revert' ones not fully valid:
sCharValidity[0xD7] = NAME_CHAR_INVALID_B;
sCharValidity[0xF7] = NAME_CHAR_INVALID_B;

/* And then we can proceed with ones only valid-as-other.
*/
sCharValidity['-'] = NAME_CHAR_VALID_NONFIRST_B;
sCharValidity['.'] = NAME_CHAR_VALID_NONFIRST_B;
sCharValidity[0xB7] = NAME_CHAR_VALID_NONFIRST_B;
for (int i = '0'; i <= '9'; ++i) {
sCharValidity[i] = NAME_CHAR_VALID_NONFIRST_B;
}
}

/**
* Public identifiers only use 7-bit ascii range.
*/
private final static int VALID_PUBID_CHAR_COUNT = 0x80;
private final static byte[] sPubidValidity = new byte[VALID_PUBID_CHAR_COUNT];
// private final static byte PUBID_CHAR_INVALID_B = (byte) 0;
private final static byte PUBID_CHAR_VALID_B = (byte) 1;
static {
for (int i = 0, last = ('z' - 'a'); i <= last; ++i) {
sPubidValidity['A' + i] = PUBID_CHAR_VALID_B;
sPubidValidity['a' + i] = PUBID_CHAR_VALID_B;
}
for (int i = '0'; i <= '9'; ++i) {
sPubidValidity[i] = PUBID_CHAR_VALID_B;
}

// 3 main white space types are valid
sPubidValidity[0x0A] = PUBID_CHAR_VALID_B;
sPubidValidity[0x0D] = PUBID_CHAR_VALID_B;
sPubidValidity[0x20] = PUBID_CHAR_VALID_B;

// And many of punctuation/separator ascii chars too:
sPubidValidity['-'] = PUBID_CHAR_VALID_B;
sPubidValidity['\''] = PUBID_CHAR_VALID_B;
sPubidValidity['('] = PUBID_CHAR_VALID_B;
sPubidValidity[')'] = PUBID_CHAR_VALID_B;
sPubidValidity['+'] = PUBID_CHAR_VALID_B;
sPubidValidity[','] = PUBID_CHAR_VALID_B;
sPubidValidity['.'] = PUBID_CHAR_VALID_B;
sPubidValidity['/'] = PUBID_CHAR_VALID_B;
sPubidValidity[':'] = PUBID_CHAR_VALID_B;
sPubidValidity['='] = PUBID_CHAR_VALID_B;
sPubidValidity['?'] = PUBID_CHAR_VALID_B;
sPubidValidity[';'] = PUBID_CHAR_VALID_B;
sPubidValidity['!'] = PUBID_CHAR_VALID_B;
sPubidValidity['*'] = PUBID_CHAR_VALID_B;
sPubidValidity['#'] = PUBID_CHAR_VALID_B;
sPubidValidity['@'] = PUBID_CHAR_VALID_B;
sPubidValidity['$'] = PUBID_CHAR_VALID_B;
sPubidValidity['_'] = PUBID_CHAR_VALID_B;
sPubidValidity['%'] = PUBID_CHAR_VALID_B;
}

/*
////////////////////////////////////////////////////
// Configuration
Expand Down
54 changes: 8 additions & 46 deletions src/main/java/com/ctc/wstx/sr/StreamScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,49 +92,11 @@ public abstract class StreamScanner
///////////////////////////////////////////////////////////////////////
*/

/**
* We will only use validity array for first 256 characters, mostly
* because after those characters it's easier to do fairly simple
* block checks.
*/
private final static int VALID_CHAR_COUNT = 0x100;

private final static byte NAME_CHAR_INVALID_B = (byte) 0;
private final static byte NAME_CHAR_ALL_VALID_B = (byte) 1;
private final static byte NAME_CHAR_VALID_NONFIRST_B = (byte) -1;

private final static byte[] sCharValidity = new byte[VALID_CHAR_COUNT];

static {
// First, since all valid-as-first chars are also valid-as-other chars,
// we'll initialize common chars:
sCharValidity['_'] = NAME_CHAR_ALL_VALID_B;
for (int i = 0, last = ('z' - 'a'); i <= last; ++i) {
sCharValidity['A' + i] = NAME_CHAR_ALL_VALID_B;
sCharValidity['a' + i] = NAME_CHAR_ALL_VALID_B;
}
for (int i = 0xC0; i < 0xF6; ++i) { // not all are fully valid, but
sCharValidity[i] = NAME_CHAR_ALL_VALID_B;
}
// ... now we can 'revert' ones not fully valid:
sCharValidity[0xD7] = NAME_CHAR_INVALID_B;
sCharValidity[0xF7] = NAME_CHAR_INVALID_B;

// And then we can proceed with ones only valid-as-other.
sCharValidity['-'] = NAME_CHAR_VALID_NONFIRST_B;
sCharValidity['.'] = NAME_CHAR_VALID_NONFIRST_B;
sCharValidity[0xB7] = NAME_CHAR_VALID_NONFIRST_B;
for (int i = '0'; i <= '9'; ++i) {
sCharValidity[i] = NAME_CHAR_VALID_NONFIRST_B;
}
}

/**
* Public identifiers only use 7-bit ascii range.
*/
private final static int VALID_PUBID_CHAR_COUNT = 0x80;
private final static byte[] sPubidValidity = new byte[VALID_PUBID_CHAR_COUNT];
// private final static byte PUBID_CHAR_INVALID_B = (byte) 0;
private final static byte PUBID_CHAR_VALID_B = (byte) 1;
static {
for (int i = 0, last = ('z' - 'a'); i <= last; ++i) {
Expand Down Expand Up @@ -401,7 +363,7 @@ protected StreamScanner(WstxInputSource input, ReaderConfig cfg,

mCfgTreatCharRefsAsEntities = mConfig.willTreatCharRefsAsEnts();
if (mCfgTreatCharRefsAsEntities) {
mCachedEntities = new HashMap<String,IntEntity>();
mCachedEntities = new HashMap<>();
} else {
mCachedEntities = Collections.emptyMap();
}
Expand Down Expand Up @@ -500,7 +462,7 @@ public void throwParseError(String format, Object arg, Object arg2)
throws XMLStreamException
{
String msg = (arg == null && arg2 == null) ? format
: MessageFormat.format(format, new Object[] { arg, arg2 });
: MessageFormat.format(format, arg, arg2);
throw constructWfcException(msg);
}

Expand All @@ -510,7 +472,7 @@ public void reportProblem(String probType, String format, Object arg, Object arg
XMLReporter rep = mConfig.getXMLReporter();
if (rep != null) {
_reportProblem(rep, probType,
MessageFormat.format(format, new Object[] { arg, arg2 }), null);
MessageFormat.format(format, arg, arg2), null);
}
}

Expand All @@ -522,7 +484,7 @@ public void reportProblem(Location loc, String probType,
XMLReporter rep = mConfig.getXMLReporter();
if (rep != null) {
String msg = (arg != null || arg2 != null) ?
MessageFormat.format(format, new Object[] { arg, arg2 }) : format;
MessageFormat.format(format, arg, arg2) : format;
_reportProblem(rep, probType, msg, loc);
}
}
Expand Down Expand Up @@ -620,7 +582,7 @@ public void reportValidationProblem(Location loc, String msg)
public void reportValidationProblem(String format, Object arg, Object arg2)
throws XMLStreamException
{
reportValidationProblem(MessageFormat.format(format, new Object[] { arg, arg2 }));
reportValidationProblem(MessageFormat.format(format, arg, arg2));
}

/*
Expand Down Expand Up @@ -1520,7 +1482,7 @@ protected int fullyResolveEntity(boolean allowExt)
char c = getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF);
// Do we have a (numeric) character entity reference?
if (c == '#') { // numeric
final StringBuffer originalSurface = new StringBuffer("#");
final StringBuilder originalSurface = new StringBuilder("#");
int ch = resolveCharEnt(originalSurface, true);
if (mCfgTreatCharRefsAsEntities) {
final char[] originalChars = new char[originalSurface.length()];
Expand Down Expand Up @@ -1590,7 +1552,7 @@ protected EntityDecl getIntEntity(int ch, final char[] originalChars)
if (ch <= 0xFFFF) {
repl = Character.toString((char) ch);
} else {
StringBuffer sb = new StringBuffer(2);
StringBuilder sb = new StringBuilder(2);
ch -= 0x10000;
sb.append((char) ((ch >> 10) + 0xD800));
sb.append((char) ((ch & 0x3FF) + 0xDC00));
Expand Down Expand Up @@ -2317,7 +2279,7 @@ protected final void parseUntil(TextBuffer tb, char endChar, boolean convertLFs,
///////////////////////////////////////////////////////////////////////
*/

private int resolveCharEnt(StringBuffer originalCharacters, boolean validateChar)
private int resolveCharEnt(StringBuilder originalCharacters, boolean validateChar)
throws XMLStreamException
{
int value = 0;
Expand Down

0 comments on commit dd14f34

Please sign in to comment.