]> OCCT Git - occt.git/commitdiff
0032299: Application Framework - Loading OCAF document saved with earlier version...
authormpv <mpv@opencascade.com>
Tue, 13 Apr 2021 15:31:31 +0000 (18:31 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 9 Jun 2021 16:46:22 +0000 (19:46 +0300)
Keeping information about the file start instead of calling tellg. This fixes problem with not-seekable streams used for XML files reading and improves performance of XML files reading (about 10%), since tellg is quite long operation.

src/LDOM/LDOMParser.cxx
src/LDOM/LDOMParser.hxx
src/LDOM/LDOM_XmlReader.cxx
src/LDOM/LDOM_XmlReader.hxx

index 341d9020673dea2af70c3a24d07853da6f0556ae..adf8d9b883d63992b5badea1077db1d9648a7d45 100644 (file)
@@ -55,13 +55,14 @@ inline
 #endif
         LDOM_XmlReader::RecordType ReadRecord (LDOM_XmlReader&  aReader,
                                                Standard_IStream& theIStream,
-                                               LDOM_OSStream&   aData)
+                                               LDOM_OSStream&   aData,
+                                               Standard_Boolean& theDocStart)
 {
 #ifdef LDOM_PARSER_TRACE
   static aCounter = 0;
   ++ aCounter;
 #endif
-  const LDOM_XmlReader::RecordType aType = aReader.ReadRecord (theIStream, aData);
+  const LDOM_XmlReader::RecordType aType = aReader.ReadRecord (theIStream, aData, theDocStart);
 #ifdef LDOM_PARSER_TRACE
   static FILE * ff = NULL;
   TCollection_AsciiString aTraceFileName;
@@ -172,11 +173,13 @@ Standard_Boolean LDOMParser::ParseDocument (std::istream& theIStream, const Stan
   Standard_Boolean      isDoctype = Standard_False;
 
   Standard_Boolean      isInsertFictRootElement = Standard_False;
+  Standard_Boolean      aDocStart = Standard_True;
+
 
   for(;;) {
     LDOM_XmlReader::RecordType aType = (theWithoutRoot && !isInsertFictRootElement ?
                                         LDOM_XmlReader::XML_START_ELEMENT : 
-                                        ReadRecord (*myReader, theIStream, myCurrentData));
+                                        ReadRecord (*myReader, theIStream, myCurrentData, aDocStart));
     switch (aType) {
     case LDOM_XmlReader::XML_HEADER:
       if (isDoctype || isElement) {
@@ -234,7 +237,7 @@ Standard_Boolean LDOMParser::ParseDocument (std::istream& theIStream, const Stan
           myError = "User abort at startElement()";
           break;
         }
-        isError = ParseElement (theIStream);
+        isError = ParseElement (theIStream, aDocStart);
         if (isError) break;
         continue;
       }
@@ -266,7 +269,7 @@ Standard_Boolean LDOMParser::ParseDocument (std::istream& theIStream, const Stan
 //purpose  : parse one element, given the type of its XML presentation
 //=======================================================================
 
-Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream)
+Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream, Standard_Boolean& theDocStart)
 {
   Standard_Boolean  isError = Standard_False;
   const LDOM_BasicElement * aParent = &myReader->GetElement();
@@ -275,7 +278,7 @@ Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream)
     LDOM_Node::NodeType aLocType;
     LDOMBasicString     aTextValue;
     char *aTextStr;
-    LDOM_XmlReader::RecordType aType = ReadRecord (* myReader, theIStream, myCurrentData);
+    LDOM_XmlReader::RecordType aType = ReadRecord (* myReader, theIStream, myCurrentData, theDocStart);
     switch (aType) {
     case LDOM_XmlReader::XML_UNKNOWN:
       isError = Standard_True;
@@ -300,7 +303,7 @@ Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream)
         myError = "User abort at startElement()";
         break;
       }
-      isError = ParseElement (theIStream);
+      isError = ParseElement (theIStream, theDocStart);
       break;
     case LDOM_XmlReader::XML_END_ELEMENT:
       {
index d064e5d019aca4aed3c6c7b0cee614f08341a803..fbcf560b2ab8e4ca94be8ca9cb2e23f1f40fe803 100644 (file)
@@ -86,7 +86,7 @@ class LDOMParser
   // ---------- PRIVATE METHODS ----------
   Standard_Boolean      ParseDocument   (Standard_IStream& theIStream, const Standard_Boolean theWithoutRoot = Standard_False);
 
-  Standard_Boolean      ParseElement    (Standard_IStream& theIStream);
+  Standard_Boolean      ParseElement    (Standard_IStream& theIStream, Standard_Boolean& theDocStart);
 
   // ---------- PRIVATE (PROHIBITED) METHODS ----------
 
index a72e9fc0c7150642bb82c0063470394b2c8322ae..17c15c90a32e0c0b412523d1ea7e21d72a6f34a5 100644 (file)
@@ -84,7 +84,8 @@ LDOM_XmlReader::LDOM_XmlReader (
 //=======================================================================
 
 LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStream,
-                                        LDOM_OSStream& theData)
+                                                       LDOM_OSStream& theData,
+                                                       Standard_Boolean& theDocStart)
 {
   theData.Clear();
   myError.Clear();
@@ -93,7 +94,6 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
   LDOMBasicString anAttrName, anAttrValue;
   char anAttDelimiter = '\0';
   Standard_Boolean aHasRead = Standard_False;
-  Standard_Boolean isFileStart = !myEOF && theIStream.tellg() == std::iostream::pos_type(0);
 
   for(;;) {
     //  Check if the current file buffer is exhausted
@@ -155,9 +155,9 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         myBuffer[aBytesRest + aNBytes] = '\0';
       }
     }
-    if (isFileStart)
+    if (theDocStart && !myEOF)
     {
-      isFileStart = Standard_False;
+      theDocStart = Standard_False;
       // check for BOM block
       Standard_Utf8UChar aFirstChar = Standard_Utf8UChar(myPtr[0]);
       switch(aFirstChar) {
index cc8965ffd067045159c56e0d0a4d7ffa33394a03..9703f025fa8a612a1789afe68c5396da1df1235d 100644 (file)
@@ -53,17 +53,19 @@ class LDOM_XmlReader
   // Constructor - takes a file descriptor for input
   // Constructor - takes an std::istream for input
 
-  RecordType            ReadRecord      (Standard_IStream& theIStream, LDOM_OSStream& theData);
+  RecordType ReadRecord (Standard_IStream& theIStream,
+                         LDOM_OSStream& theData,
+                         Standard_Boolean& theDocStart);
   // reading a markup or other element of XML format
 
-  LDOM_BasicElement&    GetElement      () const        { return * myElement; }
+  LDOM_BasicElement& GetElement() const { return * myElement; }
   // get the last element retrieved from the stream
 
   void CreateElement (const char *theName, const Standard_Integer theLen);
 
-  static Standard_Boolean getInteger    (LDOMBasicString&       theValue,
-                                         const char             * theStart,
-                                         const char             * theEnd);
+  static Standard_Boolean getInteger (LDOMBasicString&       theValue,
+                                      const char             * theStart,
+                                      const char             * theEnd);
   // try convert string theStart to LDOM_AsciiInteger, return False on success
 
   // Returns the byte order mask defined at the start of a stream