dbertoni 01/04/18 07:46:17
Modified: c/src/XPath XPath.cpp XPath.hpp XPathExpression.cpp
XPathExpression.hpp XPathProcessorImpl.cpp
Log:
Better implementation for immediate numeric literals.
Revision Changes Path
1.50 +6 -30 xml-xalan/c/src/XPath/XPath.cpp
Index: XPath.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- XPath.cpp 2001/04/12 19:00:30 1.49
+++ XPath.cpp 2001/04/18 14:46:10 1.50
@@ -298,10 +298,6 @@
return numberlit(context, opPos, executionContext);
break;
- case XPathExpression::eOP_INLINE_NUMBERLIT:
- return inlineNumberlit(context, opPos, executionContext);
- break;
-
case XPathExpression::eOP_ARGUMENT:
return arg(context, opPos, executionContext);
break;
@@ -791,18 +787,11 @@
int opPos,
XPathExecutionContext& executionContext) const
{
- if (m_expression.m_opMap[opPos] ==
XPathExpression::eOP_INLINE_NUMBERLIT)
- {
- assert(m_expression.m_opMap.size() > unsigned(opPos + 2));
-
- return double(m_expression.m_opMap[opPos + 2]);
- }
- else if (m_expression.m_opMap[opPos] == XPathExpression::eOP_NUMBERLIT)
+ if (m_expression.m_opMap[opPos] == XPathExpression::eOP_NUMBERLIT)
{
- assert(m_expression.m_opMap.size() > unsigned(opPos + 2));
- assert(m_expression.m_tokenQueue.size() >
unsigned(m_expression.m_opMap[opPos + 2]));
+ assert(m_expression.m_tokenQueue.size() >
unsigned(m_expression.m_opMap[opPos + 3]));
- return m_expression.m_tokenQueue[m_expression.m_opMap[opPos +
2]].num();
+ return m_expression.getNumberLiteral(m_expression.m_opMap[opPos
+ 2]);
}
else
{
@@ -1112,10 +1101,10 @@
int opPos,
XPathExecutionContext& executionContext) const
{
- assert(m_expression.m_opMap.size() > unsigned(opPos + 2));
- assert(m_expression.m_tokenQueue.size() >
unsigned(m_expression.m_opMap[opPos + 2]));
+ assert(m_expression.m_opMap.size() > unsigned(opPos + 3));
+ assert(m_expression.m_tokenQueue.size() >
unsigned(m_expression.m_opMap[opPos + 3]));
- const XToken& theLiteral =
m_expression.m_tokenQueue[m_expression.m_opMap[opPos + 2]];
+ const XToken& theLiteral =
m_expression.m_tokenQueue[m_expression.m_opMap[opPos + 3]];
if (m_inStylesheet == true)
{
@@ -1125,19 +1114,6 @@
{
return
executionContext.getXObjectFactory().createNumber(theLiteral.num());
}
-}
-
-
-
-const XObjectPtr
-XPath::inlineNumberlit(
- XalanNode* /* context */,
- int opPos,
- XPathExecutionContext& executionContext) const
-{
- assert(m_expression.m_opMap.size() > unsigned(opPos + 2));
-
- return
executionContext.getXObjectFactory().createNumber(m_expression.m_opMap[opPos +
2]);
}
1.23 +0 -13 xml-xalan/c/src/XPath/XPath.hpp
Index: XPath.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.hpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XPath.hpp 2001/04/11 02:21:50 1.22
+++ XPath.hpp 2001/04/18 14:46:11 1.23
@@ -774,19 +774,6 @@
XPathExecutionContext& executionContext) const;
/**
- * Get a literal value that has been placed directly in
- * the op code map of the expression
- * @param context The current source tree context node.
- * @param opPos The current position in the m_opMap array.
- * @return an XObject object.
- */
- const XObjectPtr
- inlineNumberlit(
- XalanNode* context,
- int opPos,
- XPathExecutionContext& executionContext) const;
-
- /**
* Execute a function argument.
* @param context The current source tree context node.
* @param opPos The current position in the m_opMap array.
1.28 +19 -1 xml-xalan/c/src/XPath/XPathExpression.cpp
Index: XPathExpression.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- XPathExpression.cpp 2001/04/11 02:21:50 1.27
+++ XPathExpression.cpp 2001/04/18 14:46:12 1.28
@@ -777,6 +777,25 @@
void
+XPathExpression::pushNumberLiteralOnOpCodeMap(double theNumber)
+{
+ // Get the new index for the literal...
+ const OpCodeMapValueType theIndex =
OpCodeMapValueType(m_numberLiteralValues.size());
+
+ assert(NumberLiteralValueVectorType::size_type(theIndex) ==
m_numberLiteralValues.size());
+
+ // Push the index onto the op map.
+ m_opMap.push_back(theIndex);
+
+ // Update the op map length.
+ m_opMap[s__opCodeMapLengthIndex]++;
+
+ m_numberLiteralValues.push_back(theNumber);
+}
+
+
+
+void
XPathExpression::pushCurrentTokenOnOpCodeMap()
{
assert(m_currentPosition != 0);
@@ -859,7 +878,6 @@
theMap[eMATCH_IMMEDIATE_ANCESTOR] = 1 + s__opCodeMapLengthIndex;
theMap[eMATCH_ANY_ANCESTOR_WITH_PREDICATE] = 2 +
s__opCodeMapLengthIndex;
theMap[eMATCH_ANY_ANCESTOR_WITH_FUNCTION_CALL] = 2 +
s__opCodeMapLengthIndex;
- theMap[eOP_INLINE_NUMBERLIT] = 1 + s__opCodeMapLengthIndex;
return theMap;
}
1.17 +27 -8 xml-xalan/c/src/XPath/XPathExpression.hpp
Index: XPathExpression.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XPathExpression.hpp 2001/04/11 02:21:50 1.16
+++ XPathExpression.hpp 2001/04/18 14:46:12 1.17
@@ -598,14 +598,6 @@
eMATCH_ANY_ANCESTOR_WITH_PREDICATE = 97,
eMATCH_ANY_ANCESTOR_WITH_FUNCTION_CALL = 98,
- /**
- * [OP_INLINE_NUMBERLIT] (Number literal.)
- * [3]
- * [value]
- *
- */
- eOP_INLINE_NUMBERLIT = 99,
-
// Always add _before_ this one.
eOpCodeNextAvailable
}; // enum eOpCodes
@@ -765,6 +757,7 @@
typedef vector<OpCodeMapValueType>
OpCodeMapValueVectorType;
+ typedef vector<double>
NumberLiteralValueVectorType;
#else
typedef std::vector<int> OpCodeMapType;
@@ -778,6 +771,7 @@
typedef std::set<OpCodeMapValueType> NodeTestSetType;
typedef std::vector<OpCodeMapValueType> OpCodeMapValueVectorType;
+ typedef std::vector<double>
NumberLiteralValueVectorType;
#endif
typedef TokenQueueType::value_type TokenQueueValueType;
@@ -1343,6 +1337,29 @@
pushArgumentOnOpCodeMap(double theToken);
/**
+ * Push a number literal onto the vector of number literals and its
index onto
+ * the operations code map.
+ *
+ * @param theToken number value of the token to push
+ */
+ void
+ pushNumberLiteralOnOpCodeMap(double theNumber);
+
+ /**
+ * Get a number literal from the vector of number literals.
+ *
+ * @param theIndex The index of the desired value.
+ */
+ double
+ getNumberLiteral(int theIndex) const
+ {
+ assert(theIndex >= 0 &&
+ NumberLiteralValueVectorType::size_type(theIndex) <
m_numberLiteralValues.size());
+
+ return
m_numberLiteralValues[NumberLiteralValueVectorType::size_type(theIndex)];
+ }
+
+ /**
* Push the current position in the token queue onto the operations code
* map.
*/
@@ -1475,6 +1492,8 @@
eDefaultOpMapSize = 100,
eDefaultPatternMapSize = 100
};
+
+ NumberLiteralValueVectorType m_numberLiteralValues;
// A map of Op codes to op code lengths.
const static OpCodeLengthMapType s_opCodeLengths;
1.37 +6 -31 xml-xalan/c/src/XPath/XPathProcessorImpl.cpp
Index: XPathProcessorImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- XPathProcessorImpl.cpp 2001/04/11 02:21:50 1.36
+++ XPathProcessorImpl.cpp 2001/04/18 14:46:13 1.37
@@ -1611,39 +1611,12 @@
XalanXMLChar::isDigit(charAt(m_token, 1)) ==
true) ||
XalanXMLChar::isDigit(m_tokenChar) == true)
{
- // We're going to try to save as much time as possible by
encoding
- // some things directly into the op map, instead of encoding the
- // index into the token queue.
- const double num = DoubleSupport::toDouble(m_token);
-
- const XPathExpression::OpCodeMapType::value_type
numAsValue =
- XPathExpression::OpCodeMapType::value_type(num);
-
- if (numAsValue == num)
- {
- // The value will fit directly into the token queue, so
- // put it there.
-
m_expression->appendOpCode(XPathExpression::eOP_INLINE_NUMBERLIT);
+ m_expression->appendOpCode(XPathExpression::eOP_NUMBERLIT);
- m_expression->pushValueOnOpCodeMap(numAsValue);
+ Number();
-
m_expression->updateOpCodeLength(XPathExpression::eOP_INLINE_NUMBERLIT,
-
opPos);
- }
- else
- {
- // Won't fit, so use the token to represent the number.
One way
- // to avoid this would be to use a union for the
entries in the
- // token queue, so that we can represent all numbers
in-line.
-
m_expression->appendOpCode(XPathExpression::eOP_NUMBERLIT);
-
- m_expression->pushArgumentOnOpCodeMap(num);
-
-
m_expression->updateOpCodeLength(XPathExpression::eOP_NUMBERLIT,
-
opPos);
- }
-
- nextToken();
+ m_expression->updateOpCodeLength(XPathExpression::eOP_NUMBERLIT,
+
opPos);
}
else if(lookahead(XalanUnicode::charLeftParenthesis, 1) == true ||
(lookahead(XalanUnicode::charColon, 1) == true &&
lookahead(XalanUnicode::charLeftParenthesis, 3) == true))
@@ -2219,6 +2192,8 @@
if(0 != length(m_token))
{
const double num = DoubleSupport::toDouble(m_token);
+
+ m_expression->pushNumberLiteralOnOpCodeMap(num);
m_expression->pushArgumentOnOpCodeMap(num);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]