dbertoni 2003/05/08 15:29:43
Modified: c/src/XPath XPathExpression.cpp XPathExpression.hpp
XPathProcessorImpl.cpp XToken.cpp XToken.hpp
Log:
Pool more strings to reduce memory allocations.
Revision Changes Path
1.47 +10 -4 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.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- XPathExpression.cpp 8 May 2003 18:13:21 -0000 1.46
+++ XPathExpression.cpp 8 May 2003 22:29:42 -0000 1.47
@@ -364,12 +364,16 @@
+static const XalanDOMString s_emptyString;
+
+
+
XPathExpression::XPathExpression() :
m_opMap(),
m_lastOpCodeIndex(0),
m_tokenQueue(),
m_currentPosition(0),
- m_currentPattern()
+ m_currentPattern(&s_emptyString)
{
m_opMap.reserve(eDefaultOpMapSize);
m_tokenQueue.reserve(eDefaultTokenQueueSize);
@@ -848,7 +852,7 @@
assert(thePosition < tokenQueueSize());
// Set the entry in the token queue to the XObject.
- m_tokenQueue[thePosition] = theToken;
+ m_tokenQueue[thePosition].set(theToken);
// Push the index onto the op map.
m_opMap.push_back(thePosition);
@@ -860,7 +864,9 @@
void
-XPathExpression::pushArgumentOnOpCodeMap(double theToken)
+XPathExpression::pushArgumentOnOpCodeMap(
+ double theNumber,
+ const XalanDOMString& theString)
{
assert(m_currentPosition != 0);
@@ -869,7 +875,7 @@
assert(thePosition < tokenQueueSize());
// Set the entry in the token queue to the XObject.
- m_tokenQueue[thePosition] = theToken;
+ m_tokenQueue[thePosition].set(theNumber, theString);
// Push the index onto the op map.
m_opMap.push_back(thePosition);
1.37 +50 -16 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.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- XPathExpression.hpp 8 May 2003 18:13:21 -0000 1.36
+++ XPathExpression.hpp 8 May 2003 22:29:42 -0000 1.37
@@ -1166,12 +1166,15 @@
/**
* Push a token onto the token queue.
*
- * @param theToken the number value to push
+ * @param theNumber the number value to push
+ * @param theString the string value to push
*/
void
- pushToken(double theToken)
+ pushToken(
+ double theNumber,
+ const XalanDOMString& theString)
{
- m_tokenQueue.push_back(XToken(theToken));
+ m_tokenQueue.push_back(XToken(theNumber, theString));
}
/**
@@ -1190,12 +1193,15 @@
* Insert a token onto the token queue at the
* current position.
*
- * @param theToken the string value to push
+ * @param theNumber the number value to push
+ * @param theString the string value to push
*/
void
- insertToken(double theToken)
+ insertToken(
+ double theNumber,
+ const XalanDOMString& theString)
{
- m_tokenQueue.insert(m_tokenQueue.begin() + (m_currentPosition -
1), XToken(theToken));
+ m_tokenQueue.insert(m_tokenQueue.begin() + (m_currentPosition -
1), XToken(theNumber, theString));
}
/**
@@ -1221,14 +1227,37 @@
}
/**
+ * Replace a token in the token queue.
+ *
+ * @param theOffset the offset at which to replace the token.
+ * @param theString The string data for the token. The instance will
keep a point to this string, so it must be persistent.
+ */
+ void
+ replaceRelativeToken(
+ int
theOffset,
+ const XalanDOMString& theString)
+ {
+ const int thePosition = int(m_currentPosition) +
theOffset;
+
+ if (thePosition < 0 ||
+ thePosition >= int(tokenQueueSize()))
+ {
+ throw InvalidRelativeTokenPosition(theOffset);
+ }
+
+ m_tokenQueue[thePosition].set(theString);
+ }
+
+ /**
* Diagnostic function to output the operation code map.
*
* @param thePrintWriter output device
* @param theStartPosition starting position in map
*/
void
- dumpOpCodeMap(PrintWriter& thePrintWriter,
- OpCodeMapSizeType
theStartPosition = 0) const;
+ dumpOpCodeMap(
+ PrintWriter& thePrintWriter,
+ OpCodeMapSizeType theStartPosition = 0) const;
/**
* Diagnostic function to output the operation code map.
@@ -1308,19 +1337,22 @@
* Push a token onto the token queue and its index onto the operations
code
* map.
*
- * @param theToken string value of the token to push
+ * @param theString The string data for the token. The instance will
keep a point to this string, so it must be persistent.
*/
void
- pushArgumentOnOpCodeMap(const XalanDOMString& theToken);
+ pushArgumentOnOpCodeMap(const XalanDOMString& theString);
/**
* Push a token onto the token queue and its index onto the operations
code
* map.
*
- * @param theToken number value of the token to push
+ * @param theNumber The numeric data for the token. This must be
consistent with the lexical value in theString.
+ * @param theString The string data for the token. The instance will
keep a point to this string, so it must be persistent.
*/
void
- pushArgumentOnOpCodeMap(double theToken);
+ pushArgumentOnOpCodeMap(
+ double theNumber,
+ const XalanDOMString& theString);
/**
* Push a number literal onto the vector of number literals and its
index onto
@@ -1360,7 +1392,7 @@
void
setCurrentPattern(const XalanDOMString& thePattern)
{
- m_currentPattern = thePattern;
+ m_currentPattern = &thePattern;
}
/**
@@ -1371,7 +1403,9 @@
const XalanDOMString&
getCurrentPattern() const
{
- return m_currentPattern;
+ assert(m_currentPattern != 0);
+
+ return *m_currentPattern;
}
/**
@@ -1403,7 +1437,7 @@
/**
* The current pattern string, for diagnostics purposes.
*/
- XalanDOMString m_currentPattern;
+ const XalanDOMString* m_currentPattern;
private:
@@ -1411,7 +1445,7 @@
enum
{
eDefaultOpMapSize = 100,
- eDefaultTokenQueueSize = 50,
+ eDefaultTokenQueueSize = 30,
};
NumberLiteralValueVectorType m_numberLiteralValues;
1.73 +12 -11 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.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- XPathProcessorImpl.cpp 8 May 2003 18:13:21 -0000 1.72
+++ XPathProcessorImpl.cpp 8 May 2003 22:29:42 -0000 1.73
@@ -217,7 +217,7 @@
assert(m_expression != 0);
assert(m_constructionContext != 0);
- m_expression->setCurrentPattern(pat);
+
m_expression->setCurrentPattern(m_constructionContext->getPooledString(pat));
const int nChars = length(pat);
@@ -484,7 +484,7 @@
assert(m_xpath != 0);
assert(m_expression != 0);
- m_expression->pushToken(s);
+ m_expression->pushToken(m_constructionContext->getPooledString(s));
}
@@ -504,7 +504,7 @@
m_expression->replaceRelativeToken(
-1,
- *theNamespaceURI);
+
m_constructionContext->getPooledString(*theNamespaceURI));
}
@@ -2422,13 +2422,8 @@
if(isCurrentLiteral() == true)
{
- const XPathConstructionContext::GetAndReleaseCachedString
theGuard(*m_constructionContext);
-
- XalanDOMString& theArgument = theGuard.get();
-
- theArgument.assign(m_token, 1, length(m_token) - 2);
-
- m_expression->pushArgumentOnOpCodeMap(theArgument);
+ m_expression->pushArgumentOnOpCodeMap(
+ m_constructionContext->getPooledString(m_token.c_str()
+ 1, m_token.length() - 2));
nextToken();
}
@@ -2452,9 +2447,15 @@
{
const double num = DoubleSupport::toDouble(m_token);
+ const XPathConstructionContext::GetAndReleaseCachedString
theGuard(*m_constructionContext);
+
+ XalanDOMString& theStringValue = theGuard.get();
+
+ DoubleToDOMString(num, theStringValue);
+
m_expression->pushNumberLiteralOnOpCodeMap(num);
- m_expression->pushArgumentOnOpCodeMap(num);
+ m_expression->pushArgumentOnOpCodeMap(num,
m_constructionContext->getPooledString(theStringValue));
nextToken();
}
1.10 +63 -26 xml-xalan/c/src/XPath/XToken.cpp
Index: XToken.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XToken.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XToken.cpp 22 Feb 2003 18:01:27 -0000 1.9
+++ XToken.cpp 8 May 2003 22:29:42 -0000 1.10
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -71,9 +71,11 @@
+static const XalanDOMString s_emptyString;
+
XToken::XToken() :
XObject(eTypeString),
- m_stringValue(),
+ m_stringValue(&s_emptyString),
m_numberValue(DoubleSupport::getNaN()),
m_isString(true)
{
@@ -83,7 +85,7 @@
XToken::XToken(const XalanDOMString& theString) :
XObject(eTypeString),
- m_stringValue(theString),
+ m_stringValue(&theString),
m_numberValue(DoubleSupport::toDouble(theString)),
m_isString(true)
{
@@ -91,9 +93,11 @@
-XToken::XToken(double theNumber) :
+XToken::XToken(
+ double theNumber,
+ const XalanDOMString& theString) :
XObject(eTypeString),
- m_stringValue(DoubleToDOMString(theNumber)),
+ m_stringValue(&theString),
m_numberValue(theNumber),
m_isString(false)
{
@@ -107,12 +111,14 @@
m_numberValue(theSource.m_numberValue),
m_isString(theSource.m_isString)
{
+ assert(m_stringValue != 0);
}
XToken::~XToken()
{
+ assert(m_stringValue != 0);
}
@@ -124,6 +130,8 @@
#endif
XToken::clone(void* theAddress) const
{
+ assert(m_stringValue != 0);
+
if (theAddress == 0)
{
return new XToken(*this);
@@ -139,6 +147,8 @@
XalanDOMString
XToken::getTypeString() const
{
+ assert(m_stringValue != 0);
+
return StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("#TOKEN"));
}
@@ -147,6 +157,8 @@
double
XToken::num() const
{
+ assert(m_stringValue != 0);
+
return m_numberValue;
}
@@ -155,7 +167,9 @@
bool
XToken::boolean() const
{
- return m_isString == true ? XObject::boolean(m_stringValue) :
XObject::boolean(m_numberValue);
+ assert(m_stringValue != 0);
+
+ return m_isString == true ? XObject::boolean(*m_stringValue) :
XObject::boolean(m_numberValue);
}
@@ -163,7 +177,9 @@
const XalanDOMString&
XToken::str() const
{
- return m_stringValue;
+ assert(m_stringValue != 0);
+
+ return *m_stringValue;
}
@@ -173,9 +189,10 @@
FormatterListener& formatterListener,
MemberFunctionPtr function) const
{
- assert(length(m_stringValue) ==
FormatterListener::size_type(length(m_stringValue)));
+ assert(m_stringValue != 0);
+ assert(m_stringValue->length() ==
FormatterListener::size_type(m_stringValue->length()));
- (formatterListener.*function)(c_wstr(m_stringValue),
FormatterListener::size_type(length(m_stringValue)));
+ (formatterListener.*function)(m_stringValue->c_str(),
FormatterListener::size_type(m_stringValue->length()));
}
@@ -183,7 +200,9 @@
void
XToken::str(XalanDOMString& theBuffer) const
{
- append(theBuffer, m_stringValue);
+ assert(m_stringValue != 0);
+
+ append(theBuffer, *m_stringValue);
}
@@ -191,53 +210,71 @@
double
XToken::stringLength() const
{
- return length(m_stringValue);
+ assert(m_stringValue != 0);
+
+ return length(*m_stringValue);
}
void
-XToken::ProcessXObjectTypeCallback(XObjectTypeCallback&
theCallbackObject)
+XToken::ProcessXObjectTypeCallback(XObjectTypeCallback&
theCallbackObject)
{
- theCallbackObject.String(*this, m_stringValue);
+ assert(m_stringValue != 0);
+
+ if (m_isString == true)
+ {
+ theCallbackObject.String(*this, *m_stringValue);
+ }
+ else
+ {
+ theCallbackObject.Number(*this, m_numberValue);
+ }
}
void
-XToken::ProcessXObjectTypeCallback(XObjectTypeCallback&
theCallbackObject) const
+XToken::ProcessXObjectTypeCallback(XObjectTypeCallback&
theCallbackObject) const
{
- theCallbackObject.String(*this, m_stringValue);
+ assert(m_stringValue != 0);
+
+ if (m_isString == true)
+ {
+ theCallbackObject.String(*this, *m_stringValue);
+ }
+ else
+ {
+ theCallbackObject.Number(*this, m_numberValue);
+ }
}
-XToken&
-XToken::operator=(const XalanDOMString& theString)
+void
+XToken::set(const XalanDOMString& theString)
{
- m_stringValue = theString;
+ m_stringValue = &theString;
m_numberValue = DoubleSupport::toDouble(theString);
m_isString = true;
-
- return *this;
}
-XToken&
-XToken::operator=(double theNumber)
+void
+XToken::set(
+ double theNumber,
+ const XalanDOMString& theString)
{
- clear(m_stringValue);
+ assert(theString == DoubleToDOMString(theNumber));
- DoubleToDOMString(theNumber, m_stringValue);
+ m_stringValue = &theString;
m_numberValue = theNumber;
m_isString = false;
-
- return *this;
}
1.7 +37 -11 xml-xalan/c/src/XPath/XToken.hpp
Index: XToken.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XToken.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XToken.hpp 3 Jan 2003 08:03:34 -0000 1.6
+++ XToken.hpp 8 May 2003 22:29:42 -0000 1.7
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -77,12 +77,25 @@
{
public:
- explicit
XToken();
+ /**
+ * Create an XToken for string in the token queue.
+ *
+ * @param theString The string data for the token. The instance will
keep a point to this string, so it must be persistent.
+ */
+ explicit
XToken(const XalanDOMString& theString);
- XToken(double theNumber);
+ /**
+ * Create an XToken for number in the token queue.
+ *
+ * @param theNumber The numeric data for the token. This must be
consistent with the lexical value in theString.
+ * @param theString The string data for the token. The instance will
keep a point to this string, so it must be persistent.
+ */
+ XToken(
+ double theNumber,
+ const XalanDOMString& theString);
XToken(const XToken& theSource);
@@ -135,11 +148,24 @@
return *this;
}
- XToken&
- operator=(const XalanDOMString& theString);
-
- XToken&
- operator=(double theNumber);
+ /**
+ * Set the instance as a string in the token queue.
+ *
+ * @param theString The string data for the token. XToken will keep a
point to this string, so it must be persistent.
+ */
+ void
+ set(const XalanDOMString& theString);
+
+ /**
+ * Set the instance as a number in the token queue.
+ *
+ * @param theNumber The numeric data for the token. This must be
consistent with the lexical value in theString.
+ * @param theString The string data for the token. XToken will keep a
point to this string, so it must be persistent.
+ */
+ void
+ set(
+ double theNumber,
+ const XalanDOMString& theString);
protected:
@@ -156,11 +182,11 @@
operator==(const XToken&) const;
// Data members...
- XalanDOMString m_stringValue;
+ const XalanDOMString* m_stringValue;
- double m_numberValue;
+ double m_numberValue;
- bool m_isString;
+ bool m_isString;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]