dbertoni 02/04/09 23:03:52
Modified: c/src/XMLSupport FormatterToHTML.cpp FormatterToHTML.hpp
Log:
Use dynamically-allocated map instances, for better memory leak detection.
Revision Changes Path
1.66 +54 -18 xml-xalan/c/src/XMLSupport/FormatterToHTML.cpp
Index: FormatterToHTML.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToHTML.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- FormatterToHTML.cpp 23 Feb 2002 04:21:24 -0000 1.65
+++ FormatterToHTML.cpp 10 Apr 2002 06:03:52 -0000 1.66
@@ -74,6 +74,10 @@
+#include <Include/XalanAutoPtr.hpp>
+
+
+
#include <PlatformSupport/DOMStringHelper.hpp>
#include <PlatformSupport/PrefixResolver.hpp>
#include <PlatformSupport/Writer.hpp>
@@ -125,6 +129,8 @@
m_elementLevel(0),
m_hasNamespaceStack()
{
+ assert(s_elementFlags != 0 && s_dummyDesc != 0 && s_xalanHTMLEntities
!= 0);
+
initCharsMap();
}
@@ -188,12 +194,14 @@
const FormatterToHTML::ElemDesc&
FormatterToHTML::getElemDesc(const XalanDOMChar* name)
{
+ assert(s_elementFlags != 0 && s_dummyDesc != 0);
+
const ElementFlagsMapType::const_iterator i =
- s_elementFlags.find(name);
+ s_elementFlags->find(name);
- if (i == s_elementFlags.end())
+ if (i == s_elementFlags->end())
{
- return s_dummyDesc;
+ return *s_dummyDesc;
}
else
{
@@ -522,11 +530,13 @@
XalanDOMString::size_type len,
bool escLF)
{
+ assert(s_xalanHTMLEntities != 0);
+
if(FormatterToXML::accumDefaultEntity(ch, i, chars, len, escLF) ==
false)
{
- const XalanEntityReferenceMapType::const_iterator
theIterator = s_xalanHTMLEntities.find(ch);
+ const XalanEntityReferenceMapType::const_iterator
theIterator = s_xalanHTMLEntities->find(ch);
- if (theIterator == s_xalanHTMLEntitiesIteratorEnd)
+ if (theIterator == s_xalanHTMLEntitiesIteratorEnd)
{
return false;
}
@@ -2025,16 +2035,16 @@
-static FormatterToHTML::ElementFlagsMapType s_elementFlags;
+static XalanAutoPtr<FormatterToHTML::ElementFlagsMapType> s_elementFlags;
-const FormatterToHTML::ElementFlagsMapType&
FormatterToHTML::s_elementFlags = ::s_elementFlags;
+const FormatterToHTML::ElementFlagsMapType*
FormatterToHTML::s_elementFlags = 0;
-static FormatterToHTML::XalanEntityReferenceMapType s_xalanHTMLEntities;
+static XalanAutoPtr<FormatterToHTML::XalanEntityReferenceMapType>
s_xalanHTMLEntities;
-const FormatterToHTML::XalanEntityReferenceMapType&
FormatterToHTML::s_xalanHTMLEntities = ::s_xalanHTMLEntities;
+const FormatterToHTML::XalanEntityReferenceMapType*
FormatterToHTML::s_xalanHTMLEntities = 0;
static FormatterToHTML::XalanEntityReferenceMapType::const_iterator
s_xalanHTMLEntitiesIteratorEnd;
@@ -2043,7 +2053,10 @@
const FormatterToHTML::XalanEntityReferenceMapType::const_iterator&
FormatterToHTML::s_xalanHTMLEntitiesIteratorEnd =
::s_xalanHTMLEntitiesIteratorEnd;
-const FormatterToHTML::ElemDesc
FormatterToHTML::s_dummyDesc(FormatterToHTML::ElemDesc::BLOCK);
+static XalanAutoPtr<FormatterToHTML::ElemDesc> s_dummyDesc;
+
+const FormatterToHTML::ElemDesc* FormatterToHTML::s_dummyDesc = 0;
+
static XalanDOMString s_doctypeHeaderStartString;
@@ -2089,11 +2102,19 @@
void
FormatterToHTML::initialize()
{
- initializeElementFlagsMap(::s_elementFlags);
-
- initializeXalanEntityReferenceMap(::s_xalanHTMLEntities);
-
- ::s_xalanHTMLEntitiesIteratorEnd = ::s_xalanHTMLEntities.end();
+ // Make sure there's nothing there first...
+ ::s_elementFlags.reset();
+ ::s_xalanHTMLEntities.reset();
+ ::s_dummyDesc.reset();
+
+ // New everything in a local so that an exception will clean up
everything...
+ XalanAutoPtr<ElementFlagsMapType>
theElementFlags(new ElementFlagsMapType);
+ XalanAutoPtr<XalanEntityReferenceMapType> theHTMLEntities(new
XalanEntityReferenceMapType);
+ XalanAutoPtr<FormatterToHTML::ElemDesc> theDummyDesc(new
FormatterToHTML::ElemDesc(FormatterToHTML::ElemDesc::BLOCK));
+
+ // Do initialization...
+ initializeElementFlagsMap(*theElementFlags.get());
+ initializeXalanEntityReferenceMap(*theHTMLEntities.get());
::s_doctypeHeaderStartString = XALAN_STATIC_UCODE_STRING("<!DOCTYPE
HTML");
@@ -2108,6 +2129,17 @@
::s_fnofString = XALAN_STATIC_UCODE_STRING("fnof");
::s_metaString = XALAN_STATIC_UCODE_STRING("<META
http-equiv=\"Content-Type\" content=\"text/html; charset=");
+
+ // Everythings cool, so let the globals own the objects...
+ ::s_elementFlags = theElementFlags;
+ ::s_xalanHTMLEntities = theHTMLEntities;
+ ::s_dummyDesc = theDummyDesc;
+
+ // Update the class members...
+ s_elementFlags = ::s_elementFlags.get();
+ s_xalanHTMLEntities = ::s_xalanHTMLEntities.get();
+ s_dummyDesc = ::s_dummyDesc.get();
+ ::s_xalanHTMLEntitiesIteratorEnd = ::s_xalanHTMLEntities->end();
}
@@ -2115,9 +2147,13 @@
void
FormatterToHTML::terminate()
{
- ElementFlagsMapType().swap(::s_elementFlags);
-
- XalanEntityReferenceMapType().swap(::s_xalanHTMLEntities);
+ s_elementFlags = 0;
+ s_xalanHTMLEntities = 0;
+ s_dummyDesc = 0;
+
+ ::s_elementFlags.reset();
+ ::s_xalanHTMLEntities.reset();
+ ::s_dummyDesc.reset();
releaseMemory(::s_doctypeHeaderStartString);
1.29 +4 -4 xml-xalan/c/src/XMLSupport/FormatterToHTML.hpp
Index: FormatterToHTML.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToHTML.hpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- FormatterToHTML.hpp 25 Sep 2001 21:13:17 -0000 1.28
+++ FormatterToHTML.hpp 10 Apr 2002 06:03:52 -0000 1.29
@@ -58,7 +58,7 @@
#define FORMATTERTOHTML_HEADER_GUARD_1357924680
/**
- * $Id: FormatterToHTML.hpp,v 1.28 2001/09/25 21:13:17 dbertoni Exp $
+ * $Id: FormatterToHTML.hpp,v 1.29 2002/04/10 06:03:52 dbertoni Exp $
*
* $State: Exp $
*
@@ -310,16 +310,16 @@
private:
- static const ElementFlagsMapType&
s_elementFlags;
+ static const ElementFlagsMapType*
s_elementFlags;
- static const XalanEntityReferenceMapType&
s_xalanHTMLEntities;
+ static const XalanEntityReferenceMapType*
s_xalanHTMLEntities;
static const XalanEntityReferenceMapType::const_iterator&
s_xalanHTMLEntitiesIteratorEnd;
/**
* Dummy description for elements not found.
*/
- static const ElemDesc s_dummyDesc;
+ static const ElemDesc* s_dummyDesc;
/**
* The string "<!DOCTYPE HTML".
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]