neilg 2003/09/22 12:49:03 Modified: c/src/xercesc/validators/DTD DTDGrammar.cpp DTDGrammar.hpp c/src/xercesc/validators/schema SchemaGrammar.cpp SchemaGrammar.hpp Log: implement change to Grammar::putElem(XMLElementDecl, bool). If Grammars are used only to hold declared objects, there will be no need for the fElemNonDeclPool tables; make Grammar implementations lazily create them only if the application requires them (which good cpplications should not.) Revision Changes Path 1.9 +24 -6 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DTDGrammar.cpp 14 Aug 2003 03:00:46 -0000 1.8 +++ DTDGrammar.cpp 22 Sep 2003 19:49:02 -0000 1.9 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/09/22 19:49:02 neilg + * implement change to Grammar::putElem(XMLElementDecl, bool). If Grammars are used only to hold declared objects, there will be no need for the fElemNonDeclPool tables; make Grammar implementations lazily create them only if the application requires them (which good cpplications should not.) + * * Revision 1.8 2003/08/14 03:00:46 knoaman * Code refactoring to improve performance of validation. * @@ -130,7 +133,9 @@ // pools. // fElemDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(109, 128, fMemoryManager); - fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager); + // should not need this in the common situation where grammars + // are built once and then read - NG + //fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager); fEntityDeclPool = new (fMemoryManager) NameIdPool<DTDEntityDecl>(109, 128, fMemoryManager); fNotationDeclPool = new (fMemoryManager) NameIdPool<XMLNotationDecl>(109, 128, fMemoryManager); @@ -144,7 +149,10 @@ DTDGrammar::~DTDGrammar() { delete fElemDeclPool; - delete fElemNonDeclPool; + if(fElemNonDeclPool) + { + delete fElemNonDeclPool; + } delete fEntityDeclPool; delete fNotationDeclPool; delete fGramDesc; @@ -181,6 +189,8 @@ , DTDElementDecl::Any , fMemoryManager ); + if(!fElemNonDeclPool) + fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager); const unsigned int elemId = fElemNonDeclPool->put(retVal); retVal->setId(elemId); wasAdded = true; @@ -206,9 +216,15 @@ , DTDElementDecl::Any , fMemoryManager ); - const unsigned int elemId = (notDeclared) ? fElemNonDeclPool->put(retVal) - : fElemDeclPool->put(retVal); - retVal->setId(elemId); + if(notDeclared) + { + if(!fElemNonDeclPool) + fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager); + retVal->setId(fElemNonDeclPool->put(retVal)); + } else + { + retVal->setId(fElemDeclPool->put(retVal)); + } return retVal; } @@ -218,7 +234,9 @@ // We need to reset all of the pools. // fElemDeclPool->removeAll(); - fElemNonDeclPool->removeAll(); + // now that we have this, no point in deleting it... + if(fElemNonDeclPool) + fElemNonDeclPool->removeAll(); fNotationDeclPool->removeAll(); fEntityDeclPool->removeAll(); fValidated = false; 1.10 +19 -4 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- DTDGrammar.hpp 14 Aug 2003 03:00:46 -0000 1.9 +++ DTDGrammar.hpp 22 Sep 2003 19:49:02 -0000 1.10 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.10 2003/09/22 19:49:02 neilg + * implement change to Grammar::putElem(XMLElementDecl, bool). If Grammars are used only to hold declared objects, there will be no need for the fElemNonDeclPool tables; make Grammar implementations lazily create them only if the application requires them (which good cpplications should not.) + * * Revision 1.9 2003/08/14 03:00:46 knoaman * Code refactoring to improve performance of validation. * @@ -140,6 +143,9 @@ virtual Grammar::GrammarType getGrammarType() const; virtual const XMLCh* getTargetNamespace() const; + // this method should only be used while the grammar is being + // constructed, not while it is being used + // in a validation episode! virtual XMLElementDecl* findOrAddElemDecl ( const unsigned int uriId @@ -210,7 +216,7 @@ ( XMLElementDecl* const elemDecl , const bool notDeclared = false - ) const; + ) ; virtual unsigned int putNotationDecl ( @@ -224,6 +230,9 @@ // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- + + // deprecated. returns the ID of the root element; not + // useable in multithreaded environments! unsigned int getRootElemId(); const DTDEntityDecl* getEntityDecl(const XMLCh* const entName) const; DTDEntityDecl* getEntityDecl(const XMLCh* const entName); @@ -236,6 +245,8 @@ // ----------------------------------------------------------------------- // Setter methods // ----------------------------------------------------------------------- + + // deprecated. Not usable in multithreaded environments void setRootElemId(unsigned int rootElemId); virtual void setGrammarDescription( XMLGrammarDescription*); @@ -413,7 +424,7 @@ { const XMLElementDecl* elemDecl = fElemDeclPool->getByKey(qName); - if (!elemDecl) + if (!elemDecl && fElemNonDeclPool) elemDecl = fElemNonDeclPool->getByKey(qName); return elemDecl; @@ -426,7 +437,7 @@ { XMLElementDecl* elemDecl = fElemDeclPool->getByKey(qName); - if (!elemDecl) + if (!elemDecl && fElemNonDeclPool) elemDecl = fElemNonDeclPool->getByKey(qName); return elemDecl; @@ -446,10 +457,14 @@ inline unsigned int DTDGrammar::putElemDecl(XMLElementDecl* const elemDecl, - const bool notDeclared) const + const bool notDeclared) { if (notDeclared) + { + if(!fElemNonDeclPool) + fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager); return fElemNonDeclPool->put((DTDElementDecl*) elemDecl); + } return fElemDeclPool->put((DTDElementDecl*) elemDecl); } 1.8 +21 -6 xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.cpp Index: SchemaGrammar.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SchemaGrammar.cpp 31 Jul 2003 17:12:10 -0000 1.7 +++ SchemaGrammar.cpp 22 Sep 2003 19:49:02 -0000 1.8 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.8 2003/09/22 19:49:02 neilg + * implement change to Grammar::putElem(XMLElementDecl, bool). If Grammars are used only to hold declared objects, there will be no need for the fElemNonDeclPool tables; make Grammar implementations lazily create them only if the application requires them (which good cpplications should not.) + * * Revision 1.7 2003/07/31 17:12:10 peiyongz * Grammar embed grammar description * @@ -157,7 +160,9 @@ fElemDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(109, true, 128, fMemoryManager); try { - fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); + // should not be necessary now that grammars, once built, + // are read-only + // fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); fGroupElemDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(109, false, 128, fMemoryManager); fNotationDeclPool = new (fMemoryManager) NameIdPool<XMLNotationDecl>(109, 128, fMemoryManager); fIDRefList = new (fMemoryManager) RefHashTableOf<XMLRefInfo>(29, fMemoryManager); @@ -211,6 +216,8 @@ , Grammar::TOP_LEVEL_SCOPE , fMemoryManager ); + if(!fElemNonDeclPool) + fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); const unsigned int elemId = fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal); retVal->setId(elemId); wasAdded = true; @@ -238,9 +245,15 @@ , Grammar::TOP_LEVEL_SCOPE , fMemoryManager ); - const unsigned int elemId = (notDeclared) ? fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal) - : fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal); - retVal->setId(elemId); + if(notDeclared) + { + if(!fElemNonDeclPool) + fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); + retVal->setId(fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal)); + } else + { + retVal->setId(fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal)); + } return retVal; } @@ -250,7 +263,8 @@ // We need to reset all of the pools. // fElemDeclPool->removeAll(); - fElemNonDeclPool->removeAll(); + if(fElemNonDeclPool) + fElemNonDeclPool->removeAll(); fGroupElemDeclPool->removeAll(); fNotationDeclPool->removeAll(); fValidated = false; @@ -260,7 +274,8 @@ void SchemaGrammar::cleanUp() { delete fElemDeclPool; - delete fElemNonDeclPool; + if(fElemDeclPool) + delete fElemNonDeclPool; delete fGroupElemDeclPool; delete fNotationDeclPool; fMemoryManager->deallocate(fTargetNamespace);//delete [] fTargetNamespace; 1.9 +14 -4 xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.hpp Index: SchemaGrammar.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SchemaGrammar.hpp 31 Jul 2003 17:12:10 -0000 1.8 +++ SchemaGrammar.hpp 22 Sep 2003 19:49:03 -0000 1.9 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/09/22 19:49:03 neilg + * implement change to Grammar::putElem(XMLElementDecl, bool). If Grammars are used only to hold declared objects, there will be no need for the fElemNonDeclPool tables; make Grammar implementations lazily create them only if the application requires them (which good cpplications should not.) + * * Revision 1.8 2003/07/31 17:12:10 peiyongz * Grammar embed grammar description * @@ -178,6 +181,9 @@ virtual Grammar::GrammarType getGrammarType() const; virtual const XMLCh* getTargetNamespace() const; + // this method should only be used while the grammar is being + // constructed, not while it is being used + // in a validation episode! virtual XMLElementDecl* findOrAddElemDecl ( const unsigned int uriId @@ -248,7 +254,7 @@ ( XMLElementDecl* const elemDecl , const bool notDeclared = false - ) const; + ) ; virtual unsigned int putNotationDecl ( @@ -519,7 +525,7 @@ decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope); - if (!decl) + if (!decl && fElemNonDeclPool) decl = fElemNonDeclPool->getByKey(baseName, uriId, scope); } @@ -537,7 +543,7 @@ decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope); - if (!decl) + if (!decl && fElemNonDeclPool) decl = fElemNonDeclPool->getByKey(baseName, uriId, scope); } @@ -568,10 +574,14 @@ inline unsigned int SchemaGrammar::putElemDecl(XMLElementDecl* const elemDecl, - const bool notDeclared) const + const bool notDeclared) { if (notDeclared) + { + if(!fElemNonDeclPool) + fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); return fElemNonDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl); + } return fElemDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]