knoaman 2003/08/13 20:00:46
Modified: c/src/xercesc/validators/DTD DTDGrammar.hpp DTDGrammar.cpp
Log:
Code refactoring to improve performance of validation.
Revision Changes Path
1.9 +30 -10 xml-xerces/c/src/xercesc/validators/DTD/DTDGrammar.hpp
Index: DTDGrammar.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDGrammar.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DTDGrammar.hpp 31 Jul 2003 17:09:59 -0000 1.8
+++ DTDGrammar.hpp 14 Aug 2003 03:00:46 -0000 1.9
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.9 2003/08/14 03:00:46 knoaman
+ * Code refactoring to improve performance of validation.
+ *
* Revision 1.8 2003/07/31 17:09:59 peiyongz
* Grammar embed grammar description
*
@@ -243,6 +246,12 @@
// -----------------------------------------------------------------------
unsigned int putEntityDecl(DTDEntityDecl* const entityDecl) const;
+
+ // -----------------------------------------------------------------------
+ // Notification that lazy data has been deleted
+ // -----------------------------------------------------------------------
+ static void reinitDfltEntities();
+
private:
// -----------------------------------------------------------------------
// Private helper methods
@@ -284,14 +293,15 @@
// fGramDesc: adopted
//
// -----------------------------------------------------------------------
- MemoryManager* fMemoryManager;
- NameIdPool<DTDElementDecl>* fElemDeclPool;
- NameIdPool<DTDElementDecl>* fElemNonDeclPool;
- NameIdPool<DTDEntityDecl>* fEntityDeclPool;
- NameIdPool<XMLNotationDecl>* fNotationDeclPool;
- unsigned int fRootElemId;
- bool fValidated;
- XMLDTDDescription* fGramDesc;
+ static NameIdPool<DTDEntityDecl>* fDefaultEntities;
+ MemoryManager* fMemoryManager;
+ NameIdPool<DTDElementDecl>* fElemDeclPool;
+ NameIdPool<DTDElementDecl>* fElemNonDeclPool;
+ NameIdPool<DTDEntityDecl>* fEntityDeclPool;
+ NameIdPool<XMLNotationDecl>* fNotationDeclPool;
+ unsigned int fRootElemId;
+ bool fValidated;
+ XMLDTDDescription* fGramDesc;
};
@@ -327,12 +337,22 @@
inline const DTDEntityDecl*
DTDGrammar::getEntityDecl(const XMLCh* const entName) const
{
- return fEntityDeclPool->getByKey(entName);
+ DTDEntityDecl* decl = fDefaultEntities->getByKey(entName);
+
+ if (!decl)
+ return fEntityDeclPool->getByKey(entName);
+
+ return decl;
}
inline DTDEntityDecl* DTDGrammar::getEntityDecl(const XMLCh* const entName)
{
- return fEntityDeclPool->getByKey(entName);
+ DTDEntityDecl* decl = fDefaultEntities->getByKey(entName);
+
+ if (!decl)
+ return fEntityDeclPool->getByKey(entName);
+
+ return decl;
}
1.8 +52 -22 xml-xerces/c/src/xercesc/validators/DTD/DTDGrammar.cpp
Index: DTDGrammar.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDGrammar.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DTDGrammar.cpp 31 Jul 2003 17:09:59 -0000 1.7
+++ DTDGrammar.cpp 14 Aug 2003 03:00:46 -0000 1.8
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.8 2003/08/14 03:00:46 knoaman
+ * Code refactoring to improve performance of validation.
+ *
* Revision 1.7 2003/07/31 17:09:59 peiyongz
* Grammar embed grammar description
*
@@ -97,11 +100,17 @@
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
+#include <xercesc/util/XMLRegisterCleanup.hpp>
#include <xercesc/validators/DTD/DTDGrammar.hpp>
#include <xercesc/validators/DTD/XMLDTDDescriptionImpl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
+// ---------------------------------------------------------------------------
+// DTDGrammar: Static member data
+// ---------------------------------------------------------------------------
+NameIdPool<DTDEntityDecl>* DTDGrammar::fDefaultEntities = 0;
+
//---------------------------------------------------------------------------
// DTDGrammar: Constructors and Destructor
// ---------------------------------------------------------------------------
@@ -128,12 +137,8 @@
//REVISIT: use grammarPool to create
fGramDesc = new (fMemoryManager)
XMLDTDDescriptionImpl(XMLUni::fgDTDEntityString, fMemoryManager);
- //
- // Call our own reset method. This lets us have the pool setup stuff
- // done in just one place (because this stame setup stuff has to be
- // done every time we are reset.)
- //
- reset();
+ // Create default entities
+ resetEntityDeclPool();
}
DTDGrammar::~DTDGrammar()
@@ -146,6 +151,14 @@
}
// -----------------------------------------------------------------------
+// Notification that lazy data has been deleted
+// -----------------------------------------------------------------------
+void DTDGrammar::reinitDfltEntities() {
+ delete fDefaultEntities;
+ fDefaultEntities = 0;
+}
+
+// -----------------------------------------------------------------------
// Virtual methods
// -----------------------------------------------------------------------
XMLElementDecl* DTDGrammar::findOrAddElemDecl (const unsigned int uriId
@@ -207,27 +220,44 @@
fElemDeclPool->removeAll();
fElemNonDeclPool->removeAll();
fNotationDeclPool->removeAll();
- resetEntityDeclPool();
+ fEntityDeclPool->removeAll();
fValidated = false;
}
void DTDGrammar::resetEntityDeclPool() {
- fEntityDeclPool->removeAll();
- //
- // Add the default entity entries for the character refs that must always
- // be present. We indicate that they are from the internal subset. They
- // aren't really, but they have to look that way so that they are still
- // valid for use within a standalone document.
- //
- // We also mark them as special char entities, which allows them to be
- // used in places whether other non-numeric general entities cannot.
- //
- fEntityDeclPool->put(new DTDEntityDecl(XMLUni::fgAmp, chAmpersand, true, true));
- fEntityDeclPool->put(new DTDEntityDecl(XMLUni::fgLT, chOpenAngle, true, true));
- fEntityDeclPool->put(new DTDEntityDecl(XMLUni::fgGT, chCloseAngle, true, true));
- fEntityDeclPool->put(new DTDEntityDecl(XMLUni::fgQuot, chDoubleQuote, true,
true));
- fEntityDeclPool->put(new DTDEntityDecl(XMLUni::fgApos, chSingleQuote, true,
true));
+ static XMLRegisterCleanup builtInRegistryCleanup;
+
+ // Initialize default entities if not initialized
+ if (fDefaultEntities == 0) {
+
+ NameIdPool<DTDEntityDecl>* t = new NameIdPool<DTDEntityDecl>(11, 12);
+
+ if (XMLPlatformUtils::compareAndSwap((void **)&fDefaultEntities, t, 0) != 0)
+ {
+ delete t;
+ }
+ else
+ {
+ builtInRegistryCleanup.registerCleanup(reinitDfltEntities);
+
+ //
+ // Add the default entity entries for the character refs that must
+ // always be present. We indicate that they are from the internal
+ // subset. They aren't really, but they have to look that way so
+ // that they are still valid for use within a standalone document.
+ //
+ // We also mark them as special char entities, which allows them
+ // to be used in places whether other non-numeric general entities
+ // cannot.
+ //
+ fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgAmp, chAmpersand,
true, true));
+ fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgLT, chOpenAngle,
true, true));
+ fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgGT, chCloseAngle,
true, true));
+ fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgQuot, chDoubleQuote,
true, true));
+ fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgApos, chSingleQuote,
true, true));
+ }
+ }
}
void DTDGrammar::setGrammarDescription( XMLGrammarDescription* gramDesc)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]