Skip to content

Commit 175b7dd

Browse files
committed
[optimise] Use two small and unordered Sets instead of an ordered Map
1 parent 489d11e commit 175b7dd

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/DefaultTextExtractor.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,32 @@ public class DefaultTextExtractor extends AbstractTextExtractor {
3030
private boolean addSpaceBeforeNext = false;
3131

3232
public int startElement(QName name) {
33-
if(isInlineNode(name)) {
33+
if (isInlineNode(name)) {
3434
// discard not yet applied whitespaces
3535
addSpaceBeforeNext = false;
3636
}
37-
if (config.isIgnoredNode(name) || (idxConfig != null && idxConfig.isIgnoredNode(name)))
37+
if (isIgnoredNode(name)) {
3838
stack++;
39-
else if (!isInlineNode(name) && buffer.length() > 0 && buffer.charAt(buffer.length() - 1) != ' ') {
39+
} else if (!isInlineNode(name) && buffer.length() > 0 && buffer.charAt(buffer.length() - 1) != ' ') {
4040
// separate the current element's text from preceding text
4141
buffer.append(' ');
4242
return 1;
4343
}
4444
return 0;
4545
}
4646

47-
private boolean isInlineNode(QName name) {
47+
private boolean isIgnoredNode(final QName name) {
48+
return (config.isIgnoredNode(name) || (idxConfig != null && idxConfig.isIgnoredNode(name)));
49+
}
50+
51+
private boolean isInlineNode(final QName name) {
4852
return (config.isInlineNode(name) || (idxConfig != null && idxConfig.isInlineNode(name)));
4953
}
5054

51-
public int endElement(QName name) {
52-
if (config.isIgnoredNode(name) || (idxConfig != null && idxConfig.isIgnoredNode(name)))
55+
public int endElement(final QName name) {
56+
if (isIgnoredNode(name)) {
5357
stack--;
54-
else if (!isInlineNode(name)) {
58+
} else if (!isInlineNode(name)) {
5559
// add space before following text
5660
addSpaceBeforeNext = true;
5761
}

extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/LuceneIndexConfig.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040

4141
public class LuceneIndexConfig {
4242

43-
private final static String N_INLINE = "inline";
44-
private final static String N_IGNORE = "ignore";
45-
4643
private final static String IGNORE_ELEMENT = "ignore";
4744
private final static String INLINE_ELEMENT = "inline";
4845
private final static String MATCH_ATTR_ELEMENT = "match-attribute";
@@ -65,7 +62,9 @@ public class LuceneIndexConfig {
6562

6663
private boolean isQNameIndex = false;
6764

68-
private Map<QName, String> specialNodes = null;
65+
private Set<QName> inlineNodes = null;
66+
67+
private Set<QName> ignoreNodes = null;
6968

7069
private List<AbstractFieldConfig> facetsAndFields = new ArrayList<>();
7170

@@ -144,21 +143,21 @@ private void parse(LuceneConfig parent, Element root, Map<String, String> namesp
144143
if (StringUtils.isEmpty(qnameAttr)) {
145144
throw new DatabaseConfigurationException("Lucene configuration element 'ignore' needs an attribute 'qname'");
146145
}
147-
if (specialNodes == null) {
148-
specialNodes = new TreeMap<>();
146+
if (ignoreNodes == null) {
147+
ignoreNodes = new HashSet<>(8);
149148
}
150-
specialNodes.put(parseQName(qnameAttr, namespaces), N_IGNORE);
149+
ignoreNodes.add(parseQName(qnameAttr, namespaces));
151150
break;
152151
}
153152
case INLINE_ELEMENT: {
154-
String qnameAttr = configElement.getAttribute(QNAME_ATTR);
153+
String qnameAttr = configElement.getAttribute(QNAME_ATTR);
155154
if (StringUtils.isEmpty(qnameAttr)) {
156155
throw new DatabaseConfigurationException("Lucene configuration element 'inline' needs an attribute 'qname'");
157156
}
158-
if (specialNodes == null) {
159-
specialNodes = new TreeMap<>();
157+
if (inlineNodes == null) {
158+
inlineNodes = new HashSet<>(8);
160159
}
161-
specialNodes.put(parseQName(qnameAttr, namespaces), N_INLINE);
160+
inlineNodes.add(parseQName(qnameAttr, namespaces));
162161
break;
163162
}
164163
case MATCH_SIBLING_ATTR_ELEMENT:
@@ -312,12 +311,12 @@ public boolean isNamed() {
312311
return name != null;
313312
}
314313

315-
public boolean isIgnoredNode(QName qname) {
316-
return specialNodes != null && specialNodes.get(qname) == N_IGNORE;
314+
public boolean isIgnoredNode(final QName qname) {
315+
return ignoreNodes != null && ignoreNodes.contains(qname);
317316
}
318317

319-
public boolean isInlineNode(QName qname) {
320-
return specialNodes != null && specialNodes.get(qname) == N_INLINE;
318+
public boolean isInlineNode(final QName qname) {
319+
return inlineNodes != null && inlineNodes.contains(qname);
321320
}
322321

323322
public List<AbstractFieldConfig> getFacetsAndFields() {

0 commit comments

Comments
 (0)