diff --git a/src/xercesc/internal/IGXMLScanner.cpp b/src/xercesc/internal/IGXMLScanner.cpp index cfeddbd5bda57c99ddc3e3ac6c298c43ef675539..305ffa2417a3edfa1992803e6c4b0308bccc3d02 100644 --- a/src/xercesc/internal/IGXMLScanner.cpp +++ b/src/xercesc/internal/IGXMLScanner.cpp @@ -518,6 +518,9 @@ void IGXMLScanner::commonInit() fValueStoreCache = new (fMemoryManager) ValueStoreCache(fMemoryManager); fFieldActivator = new (fMemoryManager) FieldActivator(fValueStoreCache, fMatcherStack, fMemoryManager); fValueStoreCache->setScanner(this); + + // Create schemaLocation pair info + fLocationPairs = new (fMemoryManager) ValueVectorOf<XMLCh*>(8, fMemoryManager); } void IGXMLScanner::cleanUp() @@ -529,6 +532,7 @@ void IGXMLScanner::cleanUp() delete fFieldActivator; delete fMatcherStack; delete fValueStoreCache; + delete fLocationPairs; } // --------------------------------------------------------------------------- @@ -2851,8 +2855,16 @@ Grammar* IGXMLScanner::loadDTDGrammar(const InputSource& src, } } - fDTDGrammar = new (fGrammarPoolMemoryManager) DTDGrammar(fGrammarPoolMemoryManager); - fGrammarResolver->putGrammar(fDTDGrammar); + fDTDGrammar = (DTDGrammar*) fGrammarResolver->getGrammar(XMLUni::fgDTDEntityString); + + if (fDTDGrammar) { + fDTDGrammar->reset(); + } + else { + fDTDGrammar = new (fGrammarPoolMemoryManager) DTDGrammar(fGrammarPoolMemoryManager); + fGrammarResolver->putGrammar(fDTDGrammar); + } + fGrammar = fDTDGrammar; fGrammarType = fGrammar->getGrammarType(); fValidator->setGrammar(fGrammar); @@ -2956,5 +2968,34 @@ Grammar* IGXMLScanner::loadDTDGrammar(const InputSource& src, return fDTDGrammar; } +// --------------------------------------------------------------------------- +// IGXMLScanner: Helper methods +// --------------------------------------------------------------------------- +void IGXMLScanner::processSchemaLocation(XMLCh* const schemaLoc) +{ + XMLCh* locStr = schemaLoc; + XMLReader* curReader = fReaderMgr.getCurrentReader(); + + fLocationPairs->removeAllElements(); + while (*locStr) + { + do { + if (!curReader->isWhitespace(*locStr)) + break; + + *locStr = chNull; + } while (*++locStr); + + if (*locStr) { + + fLocationPairs->addElement(locStr); + + while (*++locStr) { + if (curReader->isWhitespace(*locStr)) + break; + } + } + } +} XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/internal/IGXMLScanner.hpp b/src/xercesc/internal/IGXMLScanner.hpp index 9bc870edae10a2ca914d12141ae2b0af8bce1541..0c9f66e9572c80955d832cd092d8d463235dcef3 100644 --- a/src/xercesc/internal/IGXMLScanner.hpp +++ b/src/xercesc/internal/IGXMLScanner.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/08/14 02:56:41 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.8 2003/07/10 19:47:23 peiyongz * Stateless Grammar: Initialize scanner with grammarResolver, * creating grammar through grammarPool @@ -239,6 +242,7 @@ private : bool& skipThisOne, bool& laxThisOne); void resizeElemState(); + void processSchemaLocation(XMLCh* const schemaLoc); // ----------------------------------------------------------------------- // Private scanning methods @@ -327,6 +331,7 @@ private : XPathMatcherStack* fMatcherStack; ValueStoreCache* fValueStoreCache; FieldActivator* fFieldActivator; + ValueVectorOf<XMLCh*>* fLocationPairs; }; inline const XMLCh* IGXMLScanner::getName() const diff --git a/src/xercesc/internal/IGXMLScanner2.cpp b/src/xercesc/internal/IGXMLScanner2.cpp index 23563d48dd7e52f4244d2cca48922d339bc9e473..b571ffa9d91fcb9713d5345213865e1c6b515668 100644 --- a/src/xercesc/internal/IGXMLScanner2.cpp +++ b/src/xercesc/internal/IGXMLScanner2.cpp @@ -886,8 +886,16 @@ void IGXMLScanner::scanReset(const InputSource& src) fGrammarResolver->cacheGrammarFromParse(fToCacheGrammar); fGrammarResolver->useCachedGrammarInParse(fUseCachedGrammar); - fDTDGrammar = new (fGrammarPoolMemoryManager) DTDGrammar(fGrammarPoolMemoryManager); - fGrammarResolver->putGrammar(fDTDGrammar); + fDTDGrammar = (DTDGrammar*) fGrammarResolver->getGrammar(XMLUni::fgDTDEntityString); + + if (!fDTDGrammar) { + + fDTDGrammar = new (fGrammarPoolMemoryManager) DTDGrammar(fGrammarPoolMemoryManager); + fGrammarResolver->putGrammar(fDTDGrammar); + } + else + fDTDGrammar->reset(); + fGrammar = fDTDGrammar; fGrammarType = fGrammar->getGrammarType(); fRootGrammar = 0; @@ -1011,8 +1019,8 @@ void IGXMLScanner::sendCharData(XMLBuffer& toSend) if (fValidate) { // Get the raw data we need for the callback - const XMLCh* const rawBuf = toSend.getRawBuffer(); - const unsigned int len = toSend.getLen(); + XMLCh* rawBuf = toSend.getRawBuffer(); + unsigned int len = toSend.getLen(); // And see if the current element is a 'Children' style content model const ElemStack::StackElem* topElem = fElemStack.topElement(); @@ -1045,31 +1053,26 @@ void IGXMLScanner::sendCharData(XMLBuffer& toSend) } else { - // The normalized data can only be as large as the - // original size, so this will avoid allocating way - // too much or too little memory. - XMLBuffer toFill(len+1, fMemoryManager); - toFill.set(rawBuf); - if (fNormalizeData) { // normalize the character according to schema whitespace facet XMLBufBid bbtemp(&fBufMgr); XMLBuffer& tempBuf = bbtemp.getBuffer(); DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator(); - ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, toFill.getRawBuffer(), tempBuf); - toFill.set(tempBuf.getRawBuffer()); + ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, tempBuf); + rawBuf = tempBuf.getRawBuffer(); + len = tempBuf.getLen(); } // tell the schema validation about the character data for checkContent later - ((SchemaValidator*) fValidator)->setDatatypeBuffer(toFill.getRawBuffer()); + ((SchemaValidator*) fValidator)->setDatatypeBuffer(rawBuf); // call all active identity constraints if (fMatcherStack->getMatcherCount()) - fContent.append(toFill.getRawBuffer(), toFill.getLen()); + fContent.append(rawBuf, len); if (fDocHandler) - fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false); + fDocHandler->docCharacters(rawBuf, len, false); } } } @@ -1087,31 +1090,26 @@ void IGXMLScanner::sendCharData(XMLBuffer& toSend) } else { - // The normalized data can only be as large as the - // original size, so this will avoid allocating way - // too much or too little memory. - XMLBuffer toFill(len+1, fMemoryManager); - toFill.set(rawBuf); - if (fNormalizeData) { // normalize the character according to schema whitespace facet XMLBufBid bbtemp(&fBufMgr); XMLBuffer& tempBuf = bbtemp.getBuffer(); DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator(); - ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, toFill.getRawBuffer(), tempBuf); - toFill.set(tempBuf.getRawBuffer()); + ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, tempBuf); + rawBuf = tempBuf.getRawBuffer(); + len = tempBuf.getLen(); } // tell the schema validation about the character data for checkContent later - ((SchemaValidator*) fValidator)->setDatatypeBuffer(toFill.getRawBuffer()); + ((SchemaValidator*) fValidator)->setDatatypeBuffer(rawBuf); // call all active identity constraints if (fMatcherStack->getMatcherCount()) - fContent.append(toFill.getRawBuffer(), toFill.getLen()); + fContent.append(rawBuf, len); if (fDocHandler) - fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false); + fDocHandler->docCharacters(rawBuf, len, false); } } else @@ -1247,23 +1245,26 @@ void IGXMLScanner::scanRawAttrListforNameSpaces(const RefVectorOf<KVStringPair>* XMLBufBid bbXsi(&fBufMgr); XMLBuffer& fXsiType = bbXsi.getBuffer(); - QName attName(fMemoryManager); - for (index = 0; index < attCount; index++) { // each attribute has the prefix:suffix="value" const KVStringPair* curPair = fRawAttrList->elementAt(index); const XMLCh* rawPtr = curPair->getKey(); + const XMLCh* prefPtr = XMLUni::fgZeroLenString; + int colonInd = XMLString::indexOf(rawPtr, chColon); - attName.setName(rawPtr, fEmptyNamespaceId); - const XMLCh* prefPtr = attName.getPrefix(); + if (colonInd != -1) { + + fURIBuf.set(rawPtr, colonInd); + prefPtr = fURIBuf.getRawBuffer(); + } // if schema URI has been seen, scan for the schema location and uri // and resolve the schema grammar; or scan for schema type if (resolvePrefix(prefPtr, ElemStack::Mode_Attribute) == fSchemaNamespaceId) { const XMLCh* valuePtr = curPair->getValue(); - const XMLCh* suffPtr = attName.getLocalPart(); + const XMLCh* suffPtr = &rawPtr[colonInd + 1]; if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_SCHEMALOCACTION)) parseSchemaLocation(valuePtr); @@ -1298,17 +1299,19 @@ void IGXMLScanner::scanRawAttrListforNameSpaces(const RefVectorOf<KVStringPair>* void IGXMLScanner::parseSchemaLocation(const XMLCh* const schemaLocationStr) { - BaseRefVectorOf<XMLCh>* schemaLocation = XMLString::tokenizeString(schemaLocationStr); - unsigned int size = schemaLocation->size(); + XMLCh* locStr = XMLString::replicate(schemaLocationStr, fMemoryManager); + ArrayJanitor<XMLCh> janLoc(locStr, fMemoryManager); + + processSchemaLocation(locStr); + unsigned int size = fLocationPairs->size(); + if (size % 2 != 0 ) { emitError(XMLErrs::BadSchemaLocation); } else { for(unsigned int i=0; i<size; i=i+2) { - resolveSchemaGrammar(schemaLocation->elementAt(i+1), schemaLocation->elementAt(i)); + resolveSchemaGrammar(fLocationPairs->elementAt(i+1), fLocationPairs->elementAt(i)); } } - - delete schemaLocation; } void IGXMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri) { diff --git a/src/xercesc/internal/ReaderMgr.cpp b/src/xercesc/internal/ReaderMgr.cpp index 2e0c53e6a4db220fcc152e164dba63377920d077..727d86b4fbbeb80925c4e620a8ca4fbe061904c9 100644 --- a/src/xercesc/internal/ReaderMgr.cpp +++ b/src/xercesc/internal/ReaderMgr.cpp @@ -789,17 +789,6 @@ XMLEntityDecl* ReaderMgr::getCurrentEntity() } -const XMLReader* ReaderMgr::getCurrentReader() const -{ - return fCurReader; -} - - -XMLReader* ReaderMgr::getCurrentReader() -{ - return fCurReader; -} - unsigned int ReaderMgr::getReaderDepth() const { // If the stack doesn't exist, its obviously zero diff --git a/src/xercesc/internal/ReaderMgr.hpp b/src/xercesc/internal/ReaderMgr.hpp index 14925dda063097940ba6fabc886a67687db8a6f6..6e861a09583098339cb98b5445c8d4ff4bccde6d 100644 --- a/src/xercesc/internal/ReaderMgr.hpp +++ b/src/xercesc/internal/ReaderMgr.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.10 2003/08/14 02:56:41 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.9 2003/05/16 21:36:57 knoaman * Memory manager implementation: Modify constructors to pass in the memory manager. * @@ -387,6 +390,16 @@ inline unsigned int ReaderMgr::getCurrentReaderNum() const return fCurReader->getReaderNum(); } +inline const XMLReader* ReaderMgr::getCurrentReader() const +{ + return fCurReader; +} + +inline XMLReader* ReaderMgr::getCurrentReader() +{ + return fCurReader; +} + inline bool ReaderMgr::getName(XMLBuffer& toFill) { toFill.reset(); diff --git a/src/xercesc/internal/XMLScanner.cpp b/src/xercesc/internal/XMLScanner.cpp index 90617cd56890004e63b781a6a4ec4252451bfae2..45b2fb4e9f9a8ff6206ab7d664170f15d65a7e11 100644 --- a/src/xercesc/internal/XMLScanner.cpp +++ b/src/xercesc/internal/XMLScanner.cpp @@ -331,27 +331,51 @@ void XMLScanner::scanDocument( const XMLCh* const systemId) // Create a temporary URL. Since this is the primary document, // it has to be fully qualified. If not, then assume we are just // mistaking a file for a URL. - XMLURL tmpURL(systemId, fMemoryManager); - if (tmpURL.isRelative()) { + XMLURL tmpURL(fMemoryManager); + + if (XMLURL::parse(systemId, tmpURL)) { + + if (tmpURL.isRelative()) { + if (!fStandardUriConformant) + srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); + else { + // since this is the top of the try/catch, cannot call ThrowXML + // emit the error directly + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_NoProtocolPresent); + fInException = true; + emitError + ( + XMLErrs::XMLException_Fatal + , e.getType() + , e.getMessage() + ); + return; + } + } + else + { + if (fStandardUriConformant && tmpURL.hasInvalidChar()) { + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL); + fInException = true; + emitError + ( + XMLErrs::XMLException_Fatal + , e.getType() + , e.getMessage() + ); + return; + } + srcToUse = new (fMemoryManager) URLInputSource(tmpURL, fMemoryManager); + } + } + else { + if (!fStandardUriConformant) srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); else { // since this is the top of the try/catch, cannot call ThrowXML // emit the error directly - MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_NoProtocolPresent); - fInException = true; - emitError - ( - XMLErrs::XMLException_Fatal - , e.getType() - , e.getMessage() - ); - return; - } - } - else - { - if (fStandardUriConformant && tmpURL.hasInvalidChar()) { + // lazy bypass ... since all MalformedURLException are fatal, no need to check the type MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL); fInException = true; emitError @@ -362,29 +386,8 @@ void XMLScanner::scanDocument( const XMLCh* const systemId) ); return; } - srcToUse = new (fMemoryManager) URLInputSource(tmpURL, fMemoryManager); - } - - } - catch(const MalformedURLException& e) - { - if (!fStandardUriConformant) - srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); - else { - // since this is the top of the try/catch, cannot call ThrowXML - // emit the error directly - // lazy bypass ... since all MalformedURLException are fatal, no need to check the type - fInException = true; - emitError - ( - XMLErrs::XMLException_Fatal - , e.getType() - , e.getMessage() - ); - return; } } - catch(const XMLException& excToCatch) { // For any other XMLException, diff --git a/src/xercesc/util/XMLBigDecimal.cpp b/src/xercesc/util/XMLBigDecimal.cpp index ca230805451da0e3c9c5fcc5d6ab9d4fa62cdb27..aa8969657e53cd7d27b34def4a5d061cd75287a1 100644 --- a/src/xercesc/util/XMLBigDecimal.cpp +++ b/src/xercesc/util/XMLBigDecimal.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.10 2003/08/14 02:57:27 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.9 2003/05/16 06:01:53 knoaman * Partial implementation of the configurable memory manager. * @@ -113,10 +116,9 @@ // Includes // --------------------------------------------------------------------------- #include <xercesc/util/XMLBigDecimal.hpp> -#include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/TransService.hpp> #include <xercesc/util/NumberFormatException.hpp> -#include <xercesc/util/XMLUniDefs.hpp> +#include <xercesc/util/XMLChar.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -142,8 +144,9 @@ XMLBigDecimal::XMLBigDecimal(const XMLCh* const strValue, : fSign(0) , fTotalDigits(0) , fScale(0) -, fIntVal(0) +, fRawDataLen(0) , fRawData(0) +, fIntVal(0) , fMemoryManager(manager) { if ((!strValue) || (!*strValue)) @@ -151,8 +154,14 @@ XMLBigDecimal::XMLBigDecimal(const XMLCh* const strValue, try { - parseBigDecimal(strValue); - fRawData = XMLString::replicate(strValue, fMemoryManager); + fRawDataLen = XMLString::stringLen(strValue); + fRawData = (XMLCh*) fMemoryManager->allocate + ( + ((fRawDataLen*2) + 2) * sizeof(XMLCh) //fRawData and fIntVal + ); + memcpy(fRawData, strValue, (fRawDataLen+1) * sizeof(XMLCh)); + fIntVal = fRawData + fRawDataLen + 1; + parseBigDecimal(strValue, fRawDataLen); } catch(...) { @@ -168,18 +177,39 @@ XMLBigDecimal::~XMLBigDecimal() void XMLBigDecimal::cleanUp() { - if (fIntVal) - fMemoryManager->deallocate(fIntVal); //delete [] fIntVal; +// if (fIntVal) +// fMemoryManager->deallocate(fIntVal); //delete [] fIntVal; if (fRawData) fMemoryManager->deallocate(fRawData); //XMLString::release(&fRawData); } -void XMLBigDecimal::parseBigDecimal(const XMLCh* const toConvert) +void XMLBigDecimal::setDecimalValue(const XMLCh* const strValue) +{ + fScale = fTotalDigits = 0; + unsigned int valueLen = XMLString::stringLen(strValue); + + if (valueLen > fRawDataLen) { + + fMemoryManager->deallocate(fRawData); + fRawDataLen = valueLen; + fRawData = (XMLCh*) fMemoryManager->allocate + ( + ((fRawDataLen*2) + 2) * sizeof(XMLCh) + );//XMLString::replicate(strValue, fMemoryManager); + fIntVal = fRawData + fRawDataLen + 1; + } + + memcpy(fRawData, strValue, (valueLen + 1) * sizeof(XMLCh)); + parseBigDecimal(strValue, valueLen); +} + +void XMLBigDecimal::parseBigDecimal(const XMLCh* const toConvert + , unsigned int toConvertLen) { // Scan past any whitespace. If we hit the end, then return failure const XMLCh* startPtr = toConvert; - while (XMLPlatformUtils::fgTransService->isSpace(*startPtr)) + while (XMLChar1_0::isWhitespace(*startPtr)) startPtr++; if (!*startPtr) @@ -187,7 +217,7 @@ void XMLBigDecimal::parseBigDecimal(const XMLCh* const toConvert) // Start at the end and work back through any whitespace const XMLCh* endPtr = toConvert + XMLString::stringLen(toConvert); - while (XMLPlatformUtils::fgTransService->isSpace(*(endPtr - 1))) + while (XMLChar1_0::isWhitespace(*(endPtr - 1))) endPtr--; // '+' or '-' is allowed only at the first position @@ -211,15 +241,10 @@ void XMLBigDecimal::parseBigDecimal(const XMLCh* const toConvert) if (!*startPtr) { fSign = 0; - fIntVal = (XMLCh*) fMemoryManager->allocate(sizeof(XMLCh)); //new XMLCh[1]; fIntVal[0] = chNull; return; } - fIntVal = (XMLCh*) fMemoryManager->allocate - ( - (endPtr - startPtr + 1) * sizeof(XMLCh) - ); //new XMLCh[endPtr - startPtr + 1]; XMLCh* retPtr = fIntVal; // Scan data diff --git a/src/xercesc/util/XMLBigDecimal.hpp b/src/xercesc/util/XMLBigDecimal.hpp index a4e63d121bef8506863d78aba761497983aa7f71..8faccd319239776753336d72d6ce2eb50fc2fd8e 100644 --- a/src/xercesc/util/XMLBigDecimal.hpp +++ b/src/xercesc/util/XMLBigDecimal.hpp @@ -121,8 +121,16 @@ public: */ int toCompare(const XMLBigDecimal& other) const; + /* + * Sets the value to be converted + * + * @param strValue the value to convert + */ + void setDecimalValue(const XMLCh* const strValue); + private: - void parseBigDecimal(const XMLCh* const strValue); + void parseBigDecimal( const XMLCh* const strValue + , unsigned int strValueLen); void cleanUp(); // ----------------------------------------------------------------------- @@ -157,8 +165,9 @@ private: int fSign; unsigned int fTotalDigits; unsigned int fScale; - XMLCh* fIntVal; + unsigned int fRawDataLen; XMLCh* fRawData; + XMLCh* fIntVal; MemoryManager* fMemoryManager; }; diff --git a/src/xercesc/util/XMLChar.hpp b/src/xercesc/util/XMLChar.hpp index 3d823b3c8c11de1ee35861d45e1799023861aa8b..f1ea9041b69008dfdd984d763d1b7e4df424e9df 100644 --- a/src/xercesc/util/XMLChar.hpp +++ b/src/xercesc/util/XMLChar.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.2 2003/08/14 02:57:27 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.1 2002/12/20 22:10:21 tng * XML 1.1 * @@ -130,7 +133,8 @@ public: static bool isPlainContentChar(const XMLCh toCheck, const XMLCh toCheck2 = 0); static bool isSpecialStartTagChar(const XMLCh toCheck, const XMLCh toCheck2 = 0); static bool isXMLChar(const XMLCh toCheck, const XMLCh toCheck2 = 0); - static bool isWhitespace(const XMLCh toCheck, const XMLCh toCheck2 = 0); + static bool isWhitespace(const XMLCh toCheck); + static bool isWhitespace(const XMLCh toCheck, const XMLCh toCheck2); static bool isControlChar(const XMLCh toCheck, const XMLCh toCheck2 = 0); static bool isPublicIdChar(const XMLCh toCheck, const XMLCh toCheck2 = 0); @@ -224,6 +228,11 @@ inline bool XMLChar1_0::isXMLChar(const XMLCh toCheck, const XMLCh toCheck2) return false; } +inline bool XMLChar1_0::isWhitespace(const XMLCh toCheck) +{ + return ((fgCharCharsTable1_0[toCheck] & gWhitespaceCharMask) != 0); +} + inline bool XMLChar1_0::isWhitespace(const XMLCh toCheck, const XMLCh toCheck2) { if (!toCheck2) diff --git a/src/xercesc/util/XMLDateTime.cpp b/src/xercesc/util/XMLDateTime.cpp index 5d3b47a30ed871d98d6049eba009a46933930c2b..55e43b2159a22f8cdb1354be38adf3733e12206b 100644 --- a/src/xercesc/util/XMLDateTime.cpp +++ b/src/xercesc/util/XMLDateTime.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.13 2003/08/14 02:57:27 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.12 2003/05/22 02:10:52 knoaman * Default the memory manager. * @@ -480,7 +483,10 @@ XMLDateTime::~XMLDateTime() } XMLDateTime::XMLDateTime(MemoryManager* const manager) -: fBuffer(0) +: fStart(0) +, fEnd(0) +, fBufferMaxLen(0) +, fBuffer(0) , fMemoryManager(manager) { reset(); @@ -488,7 +494,10 @@ XMLDateTime::XMLDateTime(MemoryManager* const manager) XMLDateTime::XMLDateTime(const XMLCh* const aString, MemoryManager* const manager) -: fBuffer(0) +: fStart(0) +, fEnd(0) +, fBufferMaxLen(0) +, fBuffer(0) , fMemoryManager(manager) { setBuffer(aString); @@ -499,7 +508,8 @@ XMLDateTime::XMLDateTime(const XMLCh* const aString, // ----------------------------------------------------------------------- XMLDateTime::XMLDateTime(const XMLDateTime &toCopy) -: fBuffer(0) +: fBufferMaxLen(0) +, fBuffer(0) , fMemoryManager(toCopy.fMemoryManager) { copy(toCopy); @@ -1374,18 +1384,16 @@ int XMLDateTime::findUTCSign (const int start) // int XMLDateTime::parseInt(const int start, const int end) const { + unsigned int retVal = 0; + for (int i=start; i < end; i++) { - XMLCh* strToScan = (XMLCh*) fMemoryManager->allocate - ( - (end - start + 1) * sizeof(XMLCh) - );//new XMLCh[end - start + 1]; - ArrayJanitor<XMLCh> jname(strToScan, fMemoryManager); - XMLString::subString(strToScan, fBuffer, start, end); + if (fBuffer[i] < chDigit_0 || fBuffer[i] > chDigit_9) + break; - unsigned int retVal; - XMLString::textToBin(strToScan, retVal); + retVal = (retVal * 10) + (unsigned int) (fBuffer[i] - chDigit_0); + } - return (int) retVal; + return (int) retVal;; } // diff --git a/src/xercesc/util/XMLDateTime.hpp b/src/xercesc/util/XMLDateTime.hpp index 9957c10a8e7feba324556be4c06c2f64abee7655..a58bdeb27354e5c6306f7210b552d708c48c1d93 100644 --- a/src/xercesc/util/XMLDateTime.hpp +++ b/src/xercesc/util/XMLDateTime.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.9 2003/08/14 02:57:27 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.8 2003/05/18 14:02:05 knoaman * Memory manager implementation: pass per instance manager. * @@ -313,6 +316,7 @@ private: int fTimeZone[TIMEZONE_ARRAYSIZE]; int fStart; int fEnd; + int fBufferMaxLen; XMLCh* fBuffer; MemoryManager* fMemoryManager; }; @@ -320,8 +324,19 @@ private: inline void XMLDateTime::setBuffer(const XMLCh* const aString) { reset(); - fBuffer = XMLString::replicate(aString, fMemoryManager); - fEnd = XMLString::stringLen(fBuffer); + + fEnd = XMLString::stringLen(aString); + if (fEnd > 0) { + + if (fEnd > fBufferMaxLen) + { + fMemoryManager->deallocate(fBuffer); + fBufferMaxLen = fEnd + 8; + fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh)); + } + + memcpy(fBuffer, aString, (fEnd+1) * sizeof(XMLCh)); + } } inline void XMLDateTime::reset() @@ -333,11 +348,7 @@ inline void XMLDateTime::reset() fStart = fEnd = 0; if (fBuffer) - { - fMemoryManager->deallocate(fBuffer);//delete[] fBuffer; - fBuffer = 0; - } - + *fBuffer = 0; } inline void XMLDateTime::copy(const XMLDateTime& rhs) @@ -350,14 +361,17 @@ inline void XMLDateTime::copy(const XMLDateTime& rhs) fStart = rhs.fStart; fEnd = rhs.fEnd; - if (fBuffer) + if (fEnd > 0) { - fMemoryManager->deallocate(fBuffer);//delete[] fBuffer; - fBuffer = 0; + if (fEnd > fBufferMaxLen) + { + fMemoryManager->deallocate(fBuffer);//delete[] fBuffer; + fBufferMaxLen = rhs.fBufferMaxLen; + fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh)); + } + + memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh)); } - - if (rhs.fBuffer) - fBuffer = XMLString::replicate(rhs.fBuffer, fMemoryManager); } inline void XMLDateTime::assertBuffer() const diff --git a/src/xercesc/util/XMLURL.cpp b/src/xercesc/util/XMLURL.cpp index 8daebda84446862c12959928bbead3b31d9b12a4..4739d25f83c23bf3ef80a8f1eed208d798897456 100644 --- a/src/xercesc/util/XMLURL.cpp +++ b/src/xercesc/util/XMLURL.cpp @@ -135,6 +135,12 @@ static ProtoEntry gProtoList[XMLURL::Protocols_Count] = // !!! Keep these up to date with list above! static const unsigned int gMaxProtoLen = 4; +static const XMLCh gListOne[] = { chColon, chForwardSlash, chNull }; +static const XMLCh gListTwo[] = { chAt, chNull }; +static const XMLCh gListThree[] = { chColon, chNull }; +static const XMLCh gListFour[] = { chForwardSlash, chNull }; +static const XMLCh gListFive[] = { chPound, chQuestion, chNull }; +static const XMLCh gListSix[] = { chPound, chNull }; // --------------------------------------------------------------------------- // Local methods @@ -926,13 +932,7 @@ void XMLURL::parse(const XMLCh* const urlText) // If the : is first, we assume we have a protocol. If the / is first, // then we skip to the host processing. // - static const XMLCh listOne[] = { chColon, chForwardSlash, chNull }; - static const XMLCh listTwo[] = { chAt, chNull }; - static const XMLCh listThree[] = { chColon, chNull }; - static const XMLCh listFour[] = { chForwardSlash, chNull }; - static const XMLCh listFive[] = { chPound, chQuestion, chNull }; - static const XMLCh listSix[] = { chPound, chNull }; - XMLCh* ptr1 = XMLString::findAny(srcPtr, listOne); + XMLCh* ptr1 = XMLString::findAny(srcPtr, gListOne); XMLCh* ptr2; // If we found a protocol, then deal with it @@ -978,7 +978,7 @@ void XMLURL::parse(const XMLCh* const urlText) if (*srcPtr) { // Search from here for a / character - ptr1 = XMLString::findAny(srcPtr, listFour); + ptr1 = XMLString::findAny(srcPtr, gListFour); // // If we found something, then the host is between where @@ -1036,7 +1036,7 @@ void XMLURL::parse(const XMLCh* const urlText) // find one, then everything between the start of the host data // and the character is the user name. // - ptr1 = XMLString::findAny(fHost, listTwo); + ptr1 = XMLString::findAny(fHost, gListTwo); if (ptr1) { // Get this info out as the user name @@ -1049,7 +1049,7 @@ void XMLURL::parse(const XMLCh* const urlText) XMLString::cut(fHost, ptr1 - fHost); // Is there a password inside the user string? - ptr2 = XMLString::findAny(fUser, listThree); + ptr2 = XMLString::findAny(fUser, gListThree); if (ptr2) { // Remove it from the user name string @@ -1067,7 +1067,7 @@ void XMLURL::parse(const XMLCh* const urlText) // not at the end of the host data, then lets see if we have a // port trailing the // - ptr1 = XMLString::findAny(fHost, listThree); + ptr1 = XMLString::findAny(fHost, gListThree); if (ptr1) { // Remove it from the host name @@ -1082,7 +1082,7 @@ void XMLURL::parse(const XMLCh* const urlText) // If the host ended up empty, then toss is if (!*fHost) { - delete[] fHost; + fMemoryManager->deallocate(fHost);//delete[] fHost; fHost = 0; } } @@ -1098,7 +1098,7 @@ void XMLURL::parse(const XMLCh* const urlText) // forward slash character, or relative. Its basically everything up // to the end of the string or to any trailing query or fragment. // - ptr1 = XMLString::findAny(srcPtr, listFive); + ptr1 = XMLString::findAny(srcPtr, gListFive); if (!ptr1) { fMemoryManager->deallocate(fPath);//delete [] fPath; @@ -1137,7 +1137,7 @@ void XMLURL::parse(const XMLCh* const urlText) // separator. // srcPtr++; - ptr1 = XMLString::findAny(srcPtr, listSix); + ptr1 = XMLString::findAny(srcPtr, gListSix); fMemoryManager->deallocate(fQuery);//delete [] fQuery; if (!ptr1) { @@ -1165,6 +1165,276 @@ void XMLURL::parse(const XMLCh* const urlText) } } +bool XMLURL::parse(const XMLCh* const urlText, XMLURL& xmlURL) +{ + // Simplify things by checking for the psycho scenarios first + if (!*urlText) + return false; + + // Before we start, check if this urlText contains valid uri characters + if (!XMLUri::isURIString(urlText)) + xmlURL.fHasInvalidChar = true; + else + xmlURL.fHasInvalidChar = false; + + // + // The first thing we will do is to check for a file name, so that + // we don't waste time thinking its a URL. If its in the form x:\ + // or x:/ and x is an ASCII letter, then assume that's the deal. + // + if (((*urlText >= chLatin_A) && (*urlText <= chLatin_Z)) + || ((*urlText >= chLatin_a) && (*urlText <= chLatin_z))) + { + if (*(urlText + 1) == chColon) + { + if ((*(urlText + 2) == chForwardSlash) + || (*(urlText + 2) == chBackSlash)) + { + return false; + } + } + } + + // Get a copy of the URL that we can modify + XMLCh* srcCpy = XMLString::replicate(urlText, xmlURL.fMemoryManager); + ArrayJanitor<XMLCh> janSrcCopy(srcCpy, xmlURL.fMemoryManager); + + // + // Get a pointer now that we can run up thrown the source as we parse + // bits and pieces out of it. + // + XMLCh* srcPtr = srcCpy; + + // Run up past any spaces + while (*srcPtr) + { + if (!XMLPlatformUtils::fgTransService->isSpace(*srcPtr)) + break; + srcPtr++; + } + + // Make sure it wasn't all space + if (!*srcPtr) + return false; + + // + // Ok, the next thing we have to do is to find either a / or : character. + // If the : is first, we assume we have a protocol. If the / is first, + // then we skip to the host processing. + // + XMLCh* ptr1 = XMLString::findAny(srcPtr, gListOne); + XMLCh* ptr2; + + // If we found a protocol, then deal with it + if (ptr1) + { + if (*ptr1 == chColon) + { + // Cap the string at the colon + *ptr1 = 0; + + // And try to find it in our list of protocols + xmlURL.fProtocol = lookupByName(srcPtr); + + if (xmlURL.fProtocol == Unknown) + return false; + + // And move our source pointer up past what we've processed + srcPtr = (ptr1 + 1); + } + } + + // + // Ok, next we need to see if we have any host part. If the next + // two characters are //, then we need to check, else move on. + // + if ((*srcPtr == chForwardSlash) && (*(srcPtr + 1) == chForwardSlash)) + { + // Move up past the slashes + srcPtr += 2; + + // + // If we aren't at the end of the string, then there has to be a + // host part at this point. we will just look for the next / char + // or end of string and make all of that the host for now. + // + if (*srcPtr) + { + // Search from here for a / character + ptr1 = XMLString::findAny(srcPtr, gListFour); + + // + // If we found something, then the host is between where + // we are and what we found. Else the host is the rest of + // the content and we are done. If its empty, leave it null. + // + if (ptr1) + { + if (ptr1 != srcPtr) + { + xmlURL.fHost = (XMLCh*) xmlURL.fMemoryManager->allocate + ( + (ptr1 - srcPtr + 1) * sizeof(XMLCh) + );//new XMLCh[(ptr1 - srcPtr) + 1]; + ptr2 = xmlURL.fHost; + while (srcPtr < ptr1) + *ptr2++ = *srcPtr++; + *ptr2 = 0; + } + } + else + { + xmlURL.fHost = XMLString::replicate(srcPtr, xmlURL.fMemoryManager); + + // Update source pointer to the end + srcPtr += XMLString::stringLen(xmlURL.fHost); + } + } + } + else + { + // + // http protocol requires two forward slashes + // we didn't get them, so throw an exception + // + if (xmlURL.fProtocol == HTTP) + return false; + } + + // + // If there was a host part, then we have to grovel through it for + // all the bits and pieces it can hold. + // + if (xmlURL.fHost) + { + // + // Look for a '@' character, which indicates a user name. If we + // find one, then everything between the start of the host data + // and the character is the user name. + // + ptr1 = XMLString::findAny(xmlURL.fHost, gListTwo); + if (ptr1) + { + // Get this info out as the user name + *ptr1 = 0; + xmlURL.fUser = XMLString::replicate(xmlURL.fHost, xmlURL.fMemoryManager); + ptr1++; + + // And now cut these chars from the host string + XMLString::cut(xmlURL.fHost, ptr1 - xmlURL.fHost); + + // Is there a password inside the user string? + ptr2 = XMLString::findAny(xmlURL.fUser, gListThree); + if (ptr2) + { + // Remove it from the user name string + *ptr2 = 0; + + // And copy out the remainder to the password field + ptr2++; + xmlURL.fPassword = XMLString::replicate(ptr2, xmlURL.fMemoryManager); + } + } + + // + // Ok, so now we are at the actual host name, if any. If we are + // not at the end of the host data, then lets see if we have a + // port trailing the + // + ptr1 = XMLString::findAny(xmlURL.fHost, gListThree); + if (ptr1) + { + // Remove it from the host name + *ptr1 = 0; + + // Try to convert it to a numeric port value and store it + ptr1++; + if (!XMLString::textToBin(ptr1, xmlURL.fPortNum)) + return false; + } + + // If the host ended up empty, then toss is + if (!*(xmlURL.fHost)) + { + xmlURL.fMemoryManager->deallocate(xmlURL.fHost);//delete[] fHost; + xmlURL.fHost = 0; + } + } + + // If we are at the end, then we are done now + if (!*srcPtr) + { + return true; + } + + // + // Next is the path part. It can be absolute, i.e. starting with a + // forward slash character, or relative. Its basically everything up + // to the end of the string or to any trailing query or fragment. + // + ptr1 = XMLString::findAny(srcPtr, gListFive); + if (!ptr1) + { + xmlURL.fPath = XMLString::replicate(srcPtr, xmlURL.fMemoryManager); + return true; + } + + // Everything from where we are to what we found is the path + if (ptr1 > srcPtr) + { + xmlURL.fPath = (XMLCh*) xmlURL.fMemoryManager->allocate + ( + (ptr1 - srcPtr + 1) * sizeof(XMLCh) + );//new XMLCh[(ptr1 - srcPtr) + 1]; + ptr2 = xmlURL.fPath; + while (srcPtr < ptr1) + *ptr2++ = *srcPtr++; + *ptr2 = 0; + } + + // + // If we found a fragment, then it is the rest of the string and we + // are done. + // + if (*srcPtr == chPound) + { + srcPtr++; + xmlURL.fFragment = XMLString::replicate(srcPtr, xmlURL.fMemoryManager); + return true; + } + + // + // The query is either the rest of the string, or up to the fragment + // separator. + // + srcPtr++; + ptr1 = XMLString::findAny(srcPtr, gListSix); + if (!ptr1) + { + xmlURL.fQuery = XMLString::replicate(srcPtr, xmlURL.fMemoryManager); + return true; + } + else + { + xmlURL.fQuery = (XMLCh*) xmlURL.fMemoryManager->allocate + ( + (ptr1 - srcPtr + 1) * sizeof(XMLCh) + );//new XMLCh[(ptr1 - srcPtr) + 1]; + ptr2 = xmlURL.fQuery; + while (srcPtr < ptr1) + *ptr2++ = *srcPtr++; + *ptr2 = 0; + } + + // If we are not at the end now, then everything else is the fragment + if (*srcPtr == chPound) + { + srcPtr++; + xmlURL.fFragment = XMLString::replicate(srcPtr, xmlURL.fMemoryManager); + } + + return true; +} XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/util/XMLURL.hpp b/src/xercesc/util/XMLURL.hpp index 0dec6f9902bd5c891b8a6a217b17b73289e53984..17e5cfdfa38d4ca1500030b468dd8480dbbc4032 100644 --- a/src/xercesc/util/XMLURL.hpp +++ b/src/xercesc/util/XMLURL.hpp @@ -95,7 +95,7 @@ public: // Public static methods // ----------------------------------------------------------------------- static Protocols lookupByName(const XMLCh* const protoName); - + static bool parse(const XMLCh* urlText, XMLURL& xmlURL); // ----------------------------------------------------------------------- // Constructors and Destructor diff --git a/src/xercesc/util/regx/RegularExpression.cpp b/src/xercesc/util/regx/RegularExpression.cpp index 9990f4d5cac2920c85daa818ac8ec3ff622bed5e..655430f92316bb594b7372a98253d3ad39be6a6e 100644 --- a/src/xercesc/util/regx/RegularExpression.cpp +++ b/src/xercesc/util/regx/RegularExpression.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.14 2003/08/14 02:57:27 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.13 2003/05/25 21:42:41 knoaman * Allocate/Deallocate Context::xxx only when necessary. * @@ -171,6 +174,7 @@ RegularExpression::Context::Context(MemoryManager* const manager) : , fLimit(0) , fLength(0) , fSize(0) + , fStringMaxLen(0) , fOffsets(0) , fMatch(0) , fString(0) @@ -193,13 +197,24 @@ RegularExpression::Context::~Context() // RegularExpression::Context: Public methods // --------------------------------------------------------------------------- void RegularExpression::Context::reset(const XMLCh* const string - , const int start, const int limit + , const int stringLen + , const int start + , const int limit , const int noClosures) { - if (fString) - fMemoryManager->deallocate(fString);//delete [] fString; + if (stringLen > fStringMaxLen || !fString) { + + fStringMaxLen = stringLen; + + if (fString) + fMemoryManager->deallocate(fString); + + fString = XMLString::replicate(string, fMemoryManager); + } + else { + memcpy(fString, string, (stringLen + 1) * sizeof(XMLCh)); + } - fString = XMLString::replicate(string, fMemoryManager); fStart = start; fLimit = limit; fLength = fLimit - fStart; @@ -208,7 +223,6 @@ void RegularExpression::Context::reset(const XMLCh* const string delete fMatch; fMatch = 0; - if (fSize != noClosures) { if (fOffsets) @@ -490,7 +504,7 @@ bool RegularExpression::matches(const XMLCh* const expression, const int start, context = fContext; } - context->reset(expression, start, end, fNoClosures); + context->reset(expression, strLength, start, end, fNoClosures); } Janitor<Context> janContext(tmpContext); @@ -728,7 +742,7 @@ RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const XMLCh* const expressi context = fContext; } - context->reset(expression, start, end, fNoClosures); + context->reset(expression, strLength, start, end, fNoClosures); } Janitor<Context> janContext(tmpContext); diff --git a/src/xercesc/util/regx/RegularExpression.hpp b/src/xercesc/util/regx/RegularExpression.hpp index 86496c2a2a611101eeb3995ea555a38077d53cce..13c6c8ddc52273b8c8337f29e5c59a52ec07a32e 100644 --- a/src/xercesc/util/regx/RegularExpression.hpp +++ b/src/xercesc/util/regx/RegularExpression.hpp @@ -190,16 +190,17 @@ private: ~Context(); inline const XMLCh* getString() const { return fString; } - void reset(const XMLCh* const string, const int start, - const int limit, const int noClosures); + void reset(const XMLCh* const string, const int stringLen, + const int start, const int limit, const int noClosures); bool nextCh(XMLInt32& ch, int& offset, const short direction); bool fInUse; bool fAdoptMatch; int fStart; int fLimit; - int fLength; + int fLength; // fLimit - fStart int fSize; + int fStringMaxLen; int* fOffsets; Match* fMatch; XMLCh* fString; diff --git a/src/xercesc/validators/DTD/DTDGrammar.cpp b/src/xercesc/validators/DTD/DTDGrammar.cpp index bebdafdd698fa197a0acf3744465be77812202d3..c7478c11825b1f864605021febd3d721e0c1f5ab 100644 --- a/src/xercesc/validators/DTD/DTDGrammar.cpp +++ b/src/xercesc/validators/DTD/DTDGrammar.cpp @@ -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 @@ DTDGrammar::DTDGrammar(MemoryManager* const manager) : //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() @@ -145,6 +150,14 @@ DTDGrammar::~DTDGrammar() delete fGramDesc; } +// ----------------------------------------------------------------------- +// Notification that lazy data has been deleted +// ----------------------------------------------------------------------- +void DTDGrammar::reinitDfltEntities() { + delete fDefaultEntities; + fDefaultEntities = 0; +} + // ----------------------------------------------------------------------- // Virtual methods // ----------------------------------------------------------------------- @@ -207,27 +220,44 @@ void DTDGrammar::reset() 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) diff --git a/src/xercesc/validators/DTD/DTDGrammar.hpp b/src/xercesc/validators/DTD/DTDGrammar.hpp index c2db00a347ea180b300a5cad9c4a053e938ea1c0..784a8d428cecca2a2f2fe8d8a2b6f8ba6fab6631 100644 --- a/src/xercesc/validators/DTD/DTDGrammar.hpp +++ b/src/xercesc/validators/DTD/DTDGrammar.hpp @@ -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 @@ public: // ----------------------------------------------------------------------- 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 @@ private: // 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 @@ DTDGrammar::getNotationEnumerator() const 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; } diff --git a/src/xercesc/validators/datatype/DateDatatypeValidator.cpp b/src/xercesc/validators/datatype/DateDatatypeValidator.cpp index d50f3c508907d2eec5cec8fe010bc3b4b34a76e0..648e02a4a61145e63d9b8c9409a597f643655aa4 100644 --- a/src/xercesc/validators/datatype/DateDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/DateDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* DateDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void DateDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseDate(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/DateDatatypeValidator.hpp b/src/xercesc/validators/datatype/DateDatatypeValidator.hpp index e1c71ea5297619a3b124bb48ab9cbc50336fc0df..1af7f892b007723206f34127b1d01f88bf3ca22d 100644 --- a/src/xercesc/validators/datatype/DateDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/DateDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -125,6 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp b/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp index f881371e71073ae395f49071a2d2477533c7bffb..348e959dd06fe24fae945f640e54bbf8d4f6e486 100644 --- a/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* DateTimeDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void DateTimeDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseDateTime(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/DateTimeDatatypeValidator.hpp b/src/xercesc/validators/datatype/DateTimeDatatypeValidator.hpp index b2a60204519aa627c59af6e4113f7ccd0942801c..cb8a2a735611c0e9c64e7a61f07b2386d2b35373 100644 --- a/src/xercesc/validators/datatype/DateTimeDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/DateTimeDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -125,6 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/DateTimeValidator.cpp b/src/xercesc/validators/datatype/DateTimeValidator.cpp index c1a66d885046e0420f41672fb0696322b7693f72..e89688bf10e583943267ef059c885997eba204b0 100644 --- a/src/xercesc/validators/datatype/DateTimeValidator.cpp +++ b/src/xercesc/validators/datatype/DateTimeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.8 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.7 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -114,7 +117,10 @@ static XMLCh value2[BUF_LEN+1]; // Constructors and Destructor // --------------------------------------------------------------------------- DateTimeValidator::~DateTimeValidator() -{} +{ + if (fDateTime) + delete fDateTime; +} DateTimeValidator::DateTimeValidator( DatatypeValidator* const baseValidator @@ -123,6 +129,7 @@ DateTimeValidator::DateTimeValidator( , const ValidatorType type , MemoryManager* const manager) :AbstractNumericFacetValidator(baseValidator, facets, finalSet, type, manager) +, fDateTime(0) { //do not invoke init() here !!! } @@ -207,78 +214,75 @@ void DateTimeValidator::checkContent(const XMLCh* const content if (asBase) return; + // the derived classes' parse() method constructs an + // XMLDateTime object anc invokes appropriate XMLDateTime's + // parser to parse the content. + if (fDateTime) + fDateTime->setBuffer(content); + else + fDateTime = new (fMemoryManager) XMLDateTime(content, fMemoryManager); + + parse(fDateTime); + // must be < MaxExclusive + if ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) { - // the derived classes' parse() method constructs an - // XMLDateTime object anc invokes appropriate XMLDateTime's - // parser to parse the content. - XMLDateTime *theDate = parse(content); - Janitor<XMLDateTime> jname(theDate); - int result; - - // must be < MaxExclusive - if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0 ) + if (compareValues(fDateTime, getMaxExclusive()) != XMLDateTime::LESS_THAN) { - result = compareValues(theDate, getMaxExclusive()); - if ( result != XMLDateTime::LESS_THAN ) - { - REPORT_VALUE_ERROR(theDate - , getMaxExclusive() - , XMLExcepts::VALUE_exceed_maxExcl) - } - } + REPORT_VALUE_ERROR( fDateTime + , getMaxExclusive() + , XMLExcepts::VALUE_exceed_maxExcl) + } + } - // must be <= MaxInclusive - if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0 ) + // must be <= MaxInclusive + if ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) + { + int result = compareValues(fDateTime, getMaxInclusive()); + if ( result == XMLDateTime::GREATER_THAN || result == XMLDateTime::INDETERMINATE ) { - result = compareValues(theDate, getMaxInclusive()); - if ( result == XMLDateTime::GREATER_THAN || result == XMLDateTime::INDETERMINATE ) - { - REPORT_VALUE_ERROR(theDate - , getMaxInclusive() - , XMLExcepts::VALUE_exceed_maxIncl) - } + REPORT_VALUE_ERROR( fDateTime + , getMaxInclusive() + , XMLExcepts::VALUE_exceed_maxIncl) } + } - // must be >= MinInclusive - if ( (thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0 ) + // must be >= MinInclusive + if ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) + { + int result = compareValues(fDateTime, getMinInclusive()); + if (result == XMLDateTime::LESS_THAN || result == XMLDateTime::INDETERMINATE) { - result = compareValues(theDate, getMinInclusive()); - if (result == XMLDateTime::LESS_THAN || result == XMLDateTime::INDETERMINATE ) - { - REPORT_VALUE_ERROR(theDate - , getMinInclusive() - , XMLExcepts::VALUE_exceed_minIncl) - } + REPORT_VALUE_ERROR( fDateTime + , getMinInclusive() + , XMLExcepts::VALUE_exceed_minIncl) } + } - // must be > MinExclusive - if ( (thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0 ) + // must be > MinExclusive + if ( (thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0 ) + { + if (compareValues(fDateTime, getMinExclusive()) != XMLDateTime::GREATER_THAN) { - result = compareValues(theDate, getMinExclusive()); - if (result != XMLDateTime::GREATER_THAN) - { - REPORT_VALUE_ERROR(theDate - , getMinExclusive() - , XMLExcepts::VALUE_exceed_minExcl) - } + REPORT_VALUE_ERROR( fDateTime + , getMinExclusive() + , XMLExcepts::VALUE_exceed_minExcl) } + } - if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 && - (getEnumeration() != 0)) + if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 && + (getEnumeration() != 0)) + { + int i=0; + int enumLength = getEnumeration()->size(); + for ( ; i < enumLength; i++) { - int i=0; - int enumLength = getEnumeration()->size(); - for ( ; i < enumLength; i++) - { - if (compareValues(theDate, getEnumeration()->elementAt(i)) == XMLDateTime::EQUAL) - break; - } - - if (i == enumLength) - ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content); + if (compareValues(fDateTime, getEnumeration()->elementAt(i)) == XMLDateTime::EQUAL) + break; } + if (i == enumLength) + ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content); } } diff --git a/src/xercesc/validators/datatype/DateTimeValidator.hpp b/src/xercesc/validators/datatype/DateTimeValidator.hpp index 7d4bfe266110cccc47d9b1fc48ce387b60289b15..099b91a3803dd7edd54d7c9266c55f0f733698f5 100644 --- a/src/xercesc/validators/datatype/DateTimeValidator.hpp +++ b/src/xercesc/validators/datatype/DateTimeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.4 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.3 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -151,12 +154,15 @@ protected: // helper interface: to be implemented/overwritten by derived class // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const) = 0; + virtual void parse(XMLDateTime* const) = 0; // to be overwritten by duration virtual int compareDates(const XMLDateTime* const lValue , const XMLDateTime* const rValue , bool strict); +private: + XMLDateTime* fDateTime; }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/DayDatatypeValidator.cpp b/src/xercesc/validators/datatype/DayDatatypeValidator.cpp index b78821196cb0cd4c8ae7374ca3ebef9c3a95f282..5415b6d285b71729815739a5bb92320a5e06d553 100644 --- a/src/xercesc/validators/datatype/DayDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/DayDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* DayDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void DayDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseDay(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/DayDatatypeValidator.hpp b/src/xercesc/validators/datatype/DayDatatypeValidator.hpp index 24644bc53aff847dc33b82bf063ac77a34498b0a..1b51b2801dbcf6daa2731b8c0f0dfbfa634328e6 100644 --- a/src/xercesc/validators/datatype/DayDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/DayDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -125,6 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/DecimalDatatypeValidator.cpp b/src/xercesc/validators/datatype/DecimalDatatypeValidator.cpp index 27d4a7f096f67ec3992700786b2d70c4cc93d059..e67c0fc898e099e9668c3ecdde2dac62c93ff65a 100644 --- a/src/xercesc/validators/datatype/DecimalDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/DecimalDatatypeValidator.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.12 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.11 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -169,6 +172,7 @@ DecimalDatatypeValidator::DecimalDatatypeValidator(MemoryManager* const manager) :AbstractNumericValidator(0, 0, 0, DatatypeValidator::Decimal, manager) , fTotalDigits(0) , fFractionDigits(0) +, fCompareData(0) {} DecimalDatatypeValidator::DecimalDatatypeValidator( @@ -180,12 +184,16 @@ DecimalDatatypeValidator::DecimalDatatypeValidator( :AbstractNumericValidator(baseValidator, facets, finalSet, DatatypeValidator::Decimal, manager) , fTotalDigits(0) , fFractionDigits(0) +, fCompareData(0) { init(enums); } DecimalDatatypeValidator::~DecimalDatatypeValidator() -{} +{ + if (fCompareData) + delete fCompareData; +} // ----------------------------------------------------------------------- // Compare methods @@ -521,8 +529,10 @@ void DecimalDatatypeValidator::checkContent( const XMLCh* const content, bool as return; try { - XMLBigDecimal theValue(content, fMemoryManager); - XMLBigDecimal *theData = &theValue; + if (fCompareData) + fCompareData->setDecimalValue(content); + else + fCompareData = new (fMemoryManager) XMLBigDecimal(content, fMemoryManager); if (getEnumeration()) { @@ -530,7 +540,7 @@ void DecimalDatatypeValidator::checkContent( const XMLCh* const content, bool as int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { - if (compareValues(theData, (XMLBigDecimal*) getEnumeration()->elementAt(i)) ==0 ) + if (compareValues(fCompareData, (XMLBigDecimal*) getEnumeration()->elementAt(i)) ==0 ) break; } @@ -538,17 +548,17 @@ void DecimalDatatypeValidator::checkContent( const XMLCh* const content, bool as ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content); } - boundsCheck(theData); + boundsCheck(fCompareData); if ( (thisFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0 ) { - if ( theData->getScale() > fFractionDigits ) + if ( fCompareData->getScale() > fFractionDigits ) { - XMLString::binToText(theData->getScale(), value1, BUF_LEN, 10); + XMLString::binToText(fCompareData->getScale(), value1, BUF_LEN, 10); XMLString::binToText(fFractionDigits, value2, BUF_LEN, 10); ThrowXML3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_fractDigit - , theData->getRawData() + , fCompareData->getRawData() , value1 , value2); } @@ -556,13 +566,13 @@ void DecimalDatatypeValidator::checkContent( const XMLCh* const content, bool as if ( (thisFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0 ) { - if ( theData->getTotalDigit() > fTotalDigits ) + if ( fCompareData->getTotalDigit() > fTotalDigits ) { - XMLString::binToText(theData->getTotalDigit(), value1, BUF_LEN, 10); + XMLString::binToText(fCompareData->getTotalDigit(), value1, BUF_LEN, 10); XMLString::binToText(fTotalDigits, value2, BUF_LEN, 10); ThrowXML3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_totalDigit - , theData->getRawData() + , fCompareData->getRawData() , value1 , value2); } @@ -574,13 +584,13 @@ void DecimalDatatypeValidator::checkContent( const XMLCh* const content, bool as where i and n are integers such that |i| < 10^totalDigits and 0 <= n <= totalDigits. ***/ - if ( theData->getScale() > fTotalDigits ) + if ( fCompareData->getScale() > fTotalDigits ) { - XMLString::binToText(theData->getScale(), value1, BUF_LEN, 10); + XMLString::binToText(fCompareData->getScale(), value1, BUF_LEN, 10); XMLString::binToText(fTotalDigits, value2, BUF_LEN, 10); ThrowXML3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_totalDigit - , theData->getRawData() + , fCompareData->getRawData() , value1 , value2); } diff --git a/src/xercesc/validators/datatype/DecimalDatatypeValidator.hpp b/src/xercesc/validators/datatype/DecimalDatatypeValidator.hpp index 76f6aadce830adb9f192a73e621083c64b1bf151..74243a7626843d2a1fcae772f19015843a97e4dd 100644 --- a/src/xercesc/validators/datatype/DecimalDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/DecimalDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.7 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.6 2003/05/22 02:10:52 knoaman * Default the memory manager. * @@ -97,6 +100,8 @@ XERCES_CPP_NAMESPACE_BEGIN +class XMLBigDecimal; + class VALIDATORS_EXPORT DecimalDatatypeValidator : public AbstractNumericValidator { public: @@ -221,9 +226,9 @@ private: // Private data members // // ----------------------------------------------------------------------- - unsigned int fTotalDigits; - unsigned int fFractionDigits; - + unsigned int fTotalDigits; + unsigned int fFractionDigits; + XMLBigDecimal* fCompareData; }; // ----------------------------------------------------------------------- diff --git a/src/xercesc/validators/datatype/DurationDatatypeValidator.cpp b/src/xercesc/validators/datatype/DurationDatatypeValidator.cpp index afcadb0d7e6c188cec0c5d77379b7d31f26fb484..4b1fb9cbee40af7aee54e5bed024bde1a54a3482 100644 --- a/src/xercesc/validators/datatype/DurationDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/DurationDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* DurationDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void DurationDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseDuration(); +} + int DurationDatatypeValidator::compareDates(const XMLDateTime* const date1 , const XMLDateTime* const date2 , bool strict) diff --git a/src/xercesc/validators/datatype/DurationDatatypeValidator.hpp b/src/xercesc/validators/datatype/DurationDatatypeValidator.hpp index 744efc08e1641065f8f14c31f0947977faca5ba9..5d49e027dd46cd9825d6817458a123cac6df2391 100644 --- a/src/xercesc/validators/datatype/DurationDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/DurationDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -125,7 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); - + virtual void parse(XMLDateTime* const); virtual int compareDates(const XMLDateTime* const , const XMLDateTime* const , bool ); diff --git a/src/xercesc/validators/datatype/MonthDatatypeValidator.cpp b/src/xercesc/validators/datatype/MonthDatatypeValidator.cpp index 5e2070bc848866a5cf32cff0ada0ec019bbf1d03..8d0b599e02fc3d020d5f18131744cd654f103003 100644 --- a/src/xercesc/validators/datatype/MonthDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/MonthDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* MonthDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void MonthDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseMonth(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/MonthDatatypeValidator.hpp b/src/xercesc/validators/datatype/MonthDatatypeValidator.hpp index 8a1cc29aff9feb0a93a9efa086fbf93f121b3a0c..3c883112ecf0b24c641043cf2009fe33bffafd0e 100644 --- a/src/xercesc/validators/datatype/MonthDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/MonthDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -125,6 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/MonthDayDatatypeValidator.cpp b/src/xercesc/validators/datatype/MonthDayDatatypeValidator.cpp index 98e3147dd3b9004f22fa3c4cbb4ca4f45bc06405..de203c78b5fdac10f167b7a998c1620f5bc94865 100644 --- a/src/xercesc/validators/datatype/MonthDayDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/MonthDayDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* MonthDayDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void MonthDayDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseMonthDay(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/MonthDayDatatypeValidator.hpp b/src/xercesc/validators/datatype/MonthDayDatatypeValidator.hpp index 60cc9c06ced92bc7c11d16497254c5b05fa8361e..fb2cf5b2af0a631542cd71b650f9b96fedf7bddd 100644 --- a/src/xercesc/validators/datatype/MonthDayDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/MonthDayDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * @@ -125,6 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp b/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp index b3a6e828fea288c58ede42ced1bf10dff5f472d4..3db9153150f4676db8a7dadca04fd378ff099be4 100644 --- a/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* TimeDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void TimeDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseTime(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/TimeDatatypeValidator.hpp b/src/xercesc/validators/datatype/TimeDatatypeValidator.hpp index 1423019e2912be1f315b235b8f76a29d9efd132b..500c0e25cacc2280b7807b12edd1683a6d4cea48 100644 --- a/src/xercesc/validators/datatype/TimeDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/TimeDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:27 knoaman * Partial implementation of the configurable memory manager. * @@ -127,6 +130,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/YearDatatypeValidator.cpp b/src/xercesc/validators/datatype/YearDatatypeValidator.cpp index 8a6c8557ee7abb725af81ca343df1433d44af04a..eb2fd253a1cf1170273a4c8950f55a32f2e6a184 100644 --- a/src/xercesc/validators/datatype/YearDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/YearDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* YearDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void YearDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseYear(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/YearDatatypeValidator.hpp b/src/xercesc/validators/datatype/YearDatatypeValidator.hpp index e08c6f4358f938775e1f4829b8be431cb5dab59c..fa542a9b10e26778ac28039be8521eea7a02a7a8 100644 --- a/src/xercesc/validators/datatype/YearDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/YearDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:27 knoaman * Partial implementation of the configurable memory manager. * @@ -125,7 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); -}; + virtual void parse(XMLDateTime* const);}; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/datatype/YearMonthDatatypeValidator.cpp b/src/xercesc/validators/datatype/YearMonthDatatypeValidator.cpp index fe3183a769b701b396aac2f0ce2a9a56df78fbf1..b83161c64cb8656c6148344d4575d6c3cfde1468 100644 --- a/src/xercesc/validators/datatype/YearMonthDatatypeValidator.cpp +++ b/src/xercesc/validators/datatype/YearMonthDatatypeValidator.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.5 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * @@ -142,6 +145,11 @@ XMLDateTime* YearMonthDatatypeValidator::parse(const XMLCh* const content) return pRetDate; } +void YearMonthDatatypeValidator::parse(XMLDateTime* const pDate) +{ + pDate->parseYearMonth(); +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/datatype/YearMonthDatatypeValidator.hpp b/src/xercesc/validators/datatype/YearMonthDatatypeValidator.hpp index 81d9d8544699e26a8de08b4117517fd90bd69a84..9c36688beffab052eb09af785a59e3fd44cfb5a8 100644 --- a/src/xercesc/validators/datatype/YearMonthDatatypeValidator.hpp +++ b/src/xercesc/validators/datatype/YearMonthDatatypeValidator.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/08/14 03:00:11 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.4 2003/05/15 18:53:27 knoaman * Partial implementation of the configurable memory manager. * @@ -125,6 +128,7 @@ protected: // implementation of (DateTimeValidator's) virtual interface // ----------------------------------------------------------------------- virtual XMLDateTime* parse(const XMLCh* const); + virtual void parse(XMLDateTime* const); }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/schema/SchemaValidator.cpp b/src/xercesc/validators/schema/SchemaValidator.cpp index 3df5c0c9db0e7f4237472e164a3987bb2aae6172..ab6c66064e870e5794d2a44454c14181c91fc11a 100644 --- a/src/xercesc/validators/schema/SchemaValidator.cpp +++ b/src/xercesc/validators/schema/SchemaValidator.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.36 2003/08/14 03:01:04 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.35 2003/07/31 17:14:27 peiyongz * Grammar embed grammar description * @@ -286,6 +289,7 @@ SchemaValidator::SchemaValidator( XMLErrorReporter* const errReporter , fSeenId(false) , fXsiType(0) , fXsiTypeValidator(0) + , fNotationBuf(0) , fDatatypeBuffer(1023, manager) , fNil(false) , fTypeStack(0) @@ -297,6 +301,9 @@ SchemaValidator::~SchemaValidator() { delete fXsiType; delete fTypeStack; + + if (fNotationBuf) + delete fNotationBuf; } // --------------------------------------------------------------------------- @@ -406,12 +413,8 @@ int SchemaValidator::checkContent (XMLElementDecl* const elemDecl DatatypeValidator::ValidatorType eleDefDVType = fCurrentDV->getType(); - // if notation, need to bind URI to notation first - XMLBuffer notationBuf(1023, fMemoryManager); - // set up the entitydeclpool in ENTITYDatatypeValidator // and the idreflist in ID/IDREFDatatypeValidator - if (eleDefDVType == DatatypeValidator::List) { DatatypeValidator* itemDTV = ((ListDatatypeValidator*)fCurrentDV)->getItemTypeDTV(); DatatypeValidator::ValidatorType itemDTVType = itemDTV->getType(); @@ -473,20 +476,22 @@ int SchemaValidator::checkContent (XMLElementDecl* const elemDecl } else if (eleDefDVType == DatatypeValidator::NOTATION) { - // + // if notation, need to bind URI to notation first + if (!fNotationBuf) + fNotationBuf = new (fMemoryManager) XMLBuffer(1023, fMemoryManager); + // Make sure that this value maps to one of the // notation values in the enumList parameter. We don't have to // look it up in the notation pool (if a notation) because we // will look up the enumerated values themselves. If they are in // the notation pool (after the Grammar is parsed), then obviously // this value will be legal since it matches one of them. - // int colonPos = -1; - unsigned int uriId = getScanner()->resolveQName(value, notationBuf, ElemStack::Mode_Element, colonPos); - notationBuf.set(getScanner()->getURIText(uriId)); - notationBuf.append(chColon); - notationBuf.append(&value[colonPos + 1]); - value = notationBuf.getRawBuffer(); + unsigned int uriId = getScanner()->resolveQName(value, *fNotationBuf, ElemStack::Mode_Element, colonPos); + fNotationBuf->set(getScanner()->getURIText(uriId)); + fNotationBuf->append(chColon); + fNotationBuf->append(&value[colonPos + 1]); + value = fNotationBuf->getRawBuffer(); } if (elemDefaultValue) { @@ -1229,6 +1234,7 @@ void SchemaValidator::normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* co bool firstNonWS = false; XMLCh nextCh; const XMLCh* srcPtr = value; + XMLReader* fCurReader = getReaderMgr()->getCurrentReader(); if ((fWhiteSpace==DatatypeValidator::COLLAPSE) && fTrailing) toFill.append(chSpace); @@ -1243,14 +1249,14 @@ void SchemaValidator::normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* co } else if (fWhiteSpace == DatatypeValidator::REPLACE) { - if (getReaderMgr()->getCurrentReader()->isWhitespace(nextCh)) + if (fCurReader->isWhitespace(nextCh)) nextCh = chSpace; } else // COLLAPSE case { if (curState == InWhitespace) { - if (!getReaderMgr()->getCurrentReader()->isWhitespace(nextCh)) + if (!fCurReader->isWhitespace(nextCh)) { if (firstNonWS) toFill.append(chSpace); @@ -1265,7 +1271,7 @@ void SchemaValidator::normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* co } else if (curState == InContent) { - if (getReaderMgr()->getCurrentReader()->isWhitespace(nextCh)) + if (fCurReader->isWhitespace(nextCh)) { curState = InWhitespace; srcPtr++; @@ -1281,10 +1287,8 @@ void SchemaValidator::normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* co srcPtr++; } srcPtr--; - nextCh = *srcPtr; - if (getReaderMgr()->getCurrentReader()->isWhitespace(nextCh)) + if (fCurReader->isWhitespace(*srcPtr)) fTrailing = true; - } diff --git a/src/xercesc/validators/schema/SchemaValidator.hpp b/src/xercesc/validators/schema/SchemaValidator.hpp index be83b3ebdf64b7f899d88db593c9ba52b0a8e821..59dbe6f8e3416fa96600734c1a07ec148c8dfdc3 100644 --- a/src/xercesc/validators/schema/SchemaValidator.hpp +++ b/src/xercesc/validators/schema/SchemaValidator.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.18 2003/08/14 03:01:04 knoaman + * Code refactoring to improve performance of validation. + * * Revision 1.17 2003/05/18 14:02:08 knoaman * Memory manager implementation: pass per instance manager. * @@ -390,6 +393,7 @@ private: QName* fXsiType; bool fNil; DatatypeValidator* fXsiTypeValidator; + XMLBuffer* fNotationBuf; XMLBuffer fDatatypeBuffer; bool fTrailing; bool fSeenId;