Part of fix for Jira issue XALANJ-2375.
Lexer.tokenize was always creating an OpMapVector object with large initial
sizes. This was wasteful, because each XPath expression so tokenize might
need only a small amount of space. Instead, changed the initial size to be
equal to five times the length of the string to be tokenized, just as a
very conservative estimate. This has a significant impact on the performance
of the XPath API.
Reviewed by Christine Li (jycli () ca ! ibm ! com).
diff --git a/src/org/apache/xpath/compiler/Lexer.java b/src/org/apache/xpath/compiler/Lexer.java
index 55a492c..f185868 100644
--- a/src/org/apache/xpath/compiler/Lexer.java
+++ b/src/org/apache/xpath/compiler/Lexer.java
@@ -113,8 +113,15 @@
m_compiler.m_currentPattern = pat;
m_patternMapSize = 0;
- // This needs to grow too.
- m_compiler.m_opMap = new OpMapVector(OpMap.MAXTOKENQUEUESIZE * 5, OpMap.BLOCKTOKENQUEUESIZE * 5, OpMap.MAPINDEX_LENGTH);
+ // This needs to grow too. Use a conservative estimate that the OpMapVector
+ // needs about five time the length of the input path expression - to a
+ // maximum of MAXTOKENQUEUESIZE*5. If the OpMapVector needs to grow, grow
+ // it freely (second argument to constructor).
+ int initTokQueueSize = ((pat.length() < OpMap.MAXTOKENQUEUESIZE)
+ ? pat.length() : OpMap.MAXTOKENQUEUESIZE) * 5;
+ m_compiler.m_opMap = new OpMapVector(initTokQueueSize,
+ OpMap.BLOCKTOKENQUEUESIZE * 5,
+ OpMap.MAPINDEX_LENGTH);
int nChars = pat.length();
int startSubstring = -1;