From 0e3bfd65e54702588604d746091be5b63c1a55e5 Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sun, 26 Aug 2012 16:42:47 +0800 Subject: [PATCH] Improved performance --- src/xmlschemagenerator.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/xmlschemagenerator.cpp b/src/xmlschemagenerator.cpp index bf54051..7371e16 100644 --- a/src/xmlschemagenerator.cpp +++ b/src/xmlschemagenerator.cpp @@ -26,6 +26,9 @@ #include #include +const static size_t maxReservedSchemaBuffer = 1024 * 1024; +const static size_t maxElementSchemaBuffer = 1024; + XmlSchemaGenerator::XmlSchemaGenerator ( bool inlineSimpleType /*= true*/) : mInlineSimpleType ( inlineSimpleType ) , mGrammarType ( Grammar::SchemaGrammarType ) @@ -68,6 +71,10 @@ const wxString &XmlSchemaGenerator::generate ( Grammar::GrammarType grammarType, return mSchema; } + size_t size = len / 3; + if ( size > maxReservedSchemaBuffer ) size = maxReservedSchemaBuffer; + mSchema.Alloc ( size ); + mSchema << _T("") << getEOL(); if ( mGrammarType == Grammar::SchemaGrammarType ) mSchema << _T("") @@ -85,6 +92,8 @@ const wxString &XmlSchemaGenerator::generate ( Grammar::GrammarType grammarType, if ( mGrammarType == Grammar::SchemaGrammarType ) mSchema << _T("") << getEOL(); + mSchema.Shrink(); + return mSchema; } @@ -251,6 +260,9 @@ void XmlSchemaGenerator::generateSchema ( ElmtData &data, size_t nIndent ) } return; } + + schema.Alloc ( maxElementSchemaBuffer ); + addIndent ( schema, nIndent++ ); schema << _T("") << getEOL(); if ( data.children.size() > 0 ) @@ -353,11 +365,14 @@ void XmlSchemaGenerator::generateSchema ( ElmtData &data, size_t nIndent ) schema << _T("") << getEOL(); addIndent ( schema, --nIndent ); schema << _T("") << getEOL(); + + schema.Shrink(); } void XmlSchemaGenerator::generateDTD ( ElmtData &data, size_t WXUNUSED ( nIndent ) ) { wxString &schema = data.schema; + schema.Alloc ( maxElementSchemaBuffer ); schema << _T("") << getEOL(); } + schema.Shrink(); } bool XmlSchemaGenerator::getSequence ( std::vector &sequence,