dbertoni 01/06/14 12:24:57
Modified: c/src/XSLT FunctionFormatNumber.cpp FunctionFormatNumber.hpp
Log:
Performance enhancements.
Revision Changes Path
1.11 +79 -29 xml-xalan/c/src/XSLT/FunctionFormatNumber.cpp
Index: FunctionFormatNumber.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/FunctionFormatNumber.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FunctionFormatNumber.cpp 2000/12/06 21:19:25 1.10
+++ FunctionFormatNumber.cpp 2001/06/14 19:24:52 1.11
@@ -129,13 +129,18 @@
theDFS =
executionContext.getDecimalFormatSymbols(Constants::DEFAULT_DECIMAL_FORMAT);
}
- const XalanDOMString theString = doFormat(
- executionContext,
- context,
- theNumber,
- thePattern,
- theDFS);
+ typedef XPathExecutionContext::GetAndReleaseCachedString
GetAndReleaseCachedString;
+ GetAndReleaseCachedString theString(executionContext);
+
+ doFormat(
+ executionContext,
+ context,
+ theNumber,
+ thePattern,
+ theDFS,
+ theString.get());
+
return executionContext.getXObjectFactory().createString(theString);
}
@@ -154,28 +159,33 @@
const double theNumber =
arg1->num();
const XalanDOMString& thePattern =
arg2->str();
- const XalanDecimalFormatSymbols* theDFS = 0;
-
const XalanDOMString& theDecimalFormatName =
arg3->str();
assert(length(theDecimalFormatName) != 0);
- theDFS = executionContext.getDecimalFormatSymbols(theDecimalFormatName);
+ const XalanDecimalFormatSymbols* theDFS =
+
executionContext.getDecimalFormatSymbols(theDecimalFormatName);
if (theDFS == 0)
{
- executionContext.warn("format-number: Specified decimal-format
element not found!!!",
- context);
+ executionContext.warn(s_warningNotFoundString,
+ context);
+
theDFS =
executionContext.getDecimalFormatSymbols(Constants::DEFAULT_DECIMAL_FORMAT);
}
- const XalanDOMString theString = doFormat(
- executionContext,
- context,
- theNumber,
- thePattern,
- theDFS);
+ typedef XPathExecutionContext::GetAndReleaseCachedString
GetAndReleaseCachedString;
+ GetAndReleaseCachedString theString(executionContext);
+
+ doFormat(
+ executionContext,
+ context,
+ theNumber,
+ thePattern,
+ theDFS,
+ theString.get());
+
return executionContext.getXObjectFactory().createString(theString);
}
@@ -195,33 +205,41 @@
-XalanDOMString
+void
FunctionFormatNumber::doFormat(
XPathExecutionContext&
executionContext,
XalanNode*
context,
double
theNumber,
const XalanDOMString&
thePattern,
- const XalanDecimalFormatSymbols* theDFS)
+ const XalanDecimalFormatSymbols* theDFS,
+ XalanDOMString&
theResult)
{
if (DoubleSupport::isNaN(theNumber) == true ||
DoubleSupport::isNegativeInfinity(theNumber) == true ||
DoubleSupport::isPositiveInfinity(theNumber) == true )
{
- return DoubleToDOMString(theNumber);
+ DoubleToDOMString(theNumber, theResult);
}
else
{
- executionContext.warn(
-
StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("format-number() is not fully
implemented!")),
- context);
+ executionContext.warn(s_warningNotImplementedString, context);
+
+ if (theDFS != 0)
+ {
+ XalanDecimalFormat theFormatter(s_emptyString,
*theDFS);
- XalanDecimalFormat theFormatter;
+ theFormatter.applyLocalizedPattern(thePattern);
- theFormatter.setDecimalFormatSymbols(theDFS != 0 ? *theDFS :
XalanDecimalFormatSymbols());
+ theFormatter.format(theNumber, theResult);
+ }
+ else
+ {
+ XalanDecimalFormat theFormatter(s_emptyString,
m_decimalFormatSymbols);
- theFormatter.applyLocalizedPattern(thePattern);
+ theFormatter.applyLocalizedPattern(thePattern);
- return theFormatter.format(theNumber);
+ theFormatter.format(theNumber, theResult);
+ }
}
}
@@ -242,6 +260,38 @@
const XalanDOMString
FunctionFormatNumber::getError() const
{
- return XALAN_STATIC_UCODE_STRING(
- "The format-number() function takes two or three arguments!");
+ return XALAN_STATIC_UCODE_STRING("The format-number() function takes
two or three arguments!");
+}
+
+
+
+static XalanDOMString s_warningNotImplementedString;
+static XalanDOMString s_warningNotFoundString;
+
+
+const XalanDOMString&
FunctionFormatNumber::s_warningNotImplementedString =
+ s_warningNotImplementedString;
+
+const XalanDOMString& FunctionFormatNumber::s_warningNotFoundString =
+ s_warningNotFoundString;
+
+const XalanDOMString FunctionFormatNumber::s_emptyString;
+
+
+void
+FunctionFormatNumber::initialize()
+{
+ ::s_warningNotImplementedString =
XALAN_STATIC_UCODE_STRING("format-number() is not fully implemented!");
+
+ ::s_warningNotFoundString = XALAN_STATIC_UCODE_STRING("format-number:
Specified decimal-format element not found!");
+}
+
+
+
+void
+FunctionFormatNumber::terminate()
+{
+ releaseMemory(::s_warningNotImplementedString);
+
+ releaseMemory(::s_warningNotFoundString);
}
1.9 +27 -2 xml-xalan/c/src/XSLT/FunctionFormatNumber.hpp
Index: FunctionFormatNumber.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/FunctionFormatNumber.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FunctionFormatNumber.hpp 2000/12/06 21:19:26 1.8
+++ FunctionFormatNumber.hpp 2001/06/14 19:24:54 1.9
@@ -72,6 +72,10 @@
+#include <PlatformSupport/XalanDecimalFormatSymbols.hpp>
+
+
+
#include <XPath/Function.hpp>
@@ -88,6 +92,18 @@
{
public:
+ /**
+ * Perform static initialization. See class XSLTInit.
+ */
+ static void
+ initialize();
+
+ /**
+ * Perform static shut down. See class XSLTInit.
+ */
+ static void
+ terminate();
+
FunctionFormatNumber();
virtual
@@ -137,13 +153,14 @@
protected:
- virtual XalanDOMString
+ virtual void
doFormat(
XPathExecutionContext&
executionContext,
XalanNode*
context,
double
theNumber,
const XalanDOMString&
thePattern,
- const XalanDecimalFormatSymbols* theDFS);
+ const XalanDecimalFormatSymbols* theDFS,
+ XalanDOMString&
theResult);
private:
@@ -156,6 +173,14 @@
bool
operator==(const FunctionFormatNumber&) const;
+
+ const XalanDecimalFormatSymbols m_decimalFormatSymbols;
+
+ static const XalanDOMString& s_warningNotImplementedString;
+
+ static const XalanDOMString& s_warningNotFoundString;
+
+ static const XalanDOMString s_emptyString;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]