]> OCCT Git - occt.git/commitdiff
0033350: Data Exchange, Step Import - Improving parsing performance IR-2023-05-12
authordpasukhi <dpasukhi@opencascade.com>
Wed, 22 Mar 2023 18:22:44 +0000 (18:22 +0000)
committervglukhik <vglukhik@opencascade.com>
Sun, 14 May 2023 20:40:28 +0000 (21:40 +0100)
Improved performance of parser by disable checking for eof (20% parsing time)
Changed step parser's record to keep last one to fast insert into end.

src/StepFile/StepFile_ReadData.cxx
src/StepFile/lex.step.cxx
src/StepFile/step.lex

index 98054dc1286fd2145fc723019af43fa9a34a5608..fe88768263d95a7971b16a8a17f080ad9570068b 100644 (file)
@@ -35,20 +35,21 @@ class StepFile_ReadData::CharactersPage {
 
 public:
 
-  CharactersPage(const Standard_Integer theMaxCar) :myNext(NULL), myUsed(0)
+  CharactersPage(const Standard_Integer theMaxCar) :myNext(nullptr), myUsed(0)
   {
     myCharacters = new char[theMaxCar];
   }
 
   ~CharactersPage()
   {
-    if (myCharacters != NULL)
+    if (myCharacters != nullptr)
     {
       delete[] myCharacters;
-      myCharacters = NULL;
+      myCharacters = nullptr;
     }
   }
 
+  DEFINE_STANDARD_ALLOC
 public:
 
   CharactersPage* myNext; //!< Chaining of character pages
@@ -64,7 +65,7 @@ public:
 
 public:
 
-  Argument() :myNext(NULL), myValue(NULL), myType(Interface_ParamSub) {}
+  Argument() :myNext(nullptr), myValue(nullptr), myType(Interface_ParamSub) {}
 
   ~Argument() {}
 
@@ -83,7 +84,7 @@ public:
 
 public:
 
-  ArgumentsPage(Standard_Integer theMaxArg) :myNext(NULL), myUsed(0)
+  ArgumentsPage(Standard_Integer theMaxArg) :myNext(nullptr), myUsed(0)
   {
     myArgs = new Argument[theMaxArg];
   }
@@ -91,7 +92,7 @@ public:
   ~ArgumentsPage()
   {
     delete[] myArgs;
-    myArgs = NULL;
+    myArgs = nullptr;
   }
 
 public:
@@ -109,7 +110,7 @@ public:
 
 public:
 
-  Record() :myNext(NULL), myFirst(NULL), myIdent(NULL), myType(NULL) {}
+  Record() :myNext(nullptr), myFirst(nullptr), myLast(nullptr), myIdent(nullptr), myType(nullptr) {}
 
   ~Record() {}
 
@@ -117,6 +118,7 @@ public:
 
   Record* myNext;    //!< Next record in the list
   Argument* myFirst; //!< First argument in the record
+  Argument* myLast;  //!< Last argument in the record
   char* myIdent;     //!< Record identifier (Example: "#12345") or scope-end
   char* myType;      //!< Type of the record
 };
@@ -129,14 +131,14 @@ public:
 
 public:
 
-  Scope() :myPrevious(NULL), myRecord(NULL) {}
+  Scope() :myPrevious(nullptr), myRecord(nullptr) {}
 
   ~Scope()
   {
-    if (myRecord != NULL)
+    if (myRecord != nullptr)
     {
       delete[] myRecord;
-      myRecord = NULL;
+      myRecord = nullptr;
     }
   }
 
@@ -151,20 +153,20 @@ class StepFile_ReadData::RecordsPage
 
 public:
 
-  RecordsPage(const Standard_Integer theMaxRec) :myNext(NULL), myUsed(0)
+  RecordsPage(const Standard_Integer theMaxRec) :myNext(nullptr), myUsed(0)
   {
     myRecords = new Record[theMaxRec];
   }
 
   ~RecordsPage()
   {
-    if (myRecords != NULL)
+    if (myRecords != nullptr)
     {
       delete[] myRecords;
-      myRecords = NULL;
+      myRecords = nullptr;
     }
   }
-
+  DEFINE_STANDARD_ALLOC
 public:
 
   RecordsPage* myNext; //!< Chaining of records pages
@@ -177,7 +179,7 @@ class StepFile_ReadData::ErrorsPage
 
 public:
 
-  ErrorsPage(Standard_CString theError) :myNext(NULL), myError(theError)
+  ErrorsPage(Standard_CString theError) :myNext(nullptr), myError(theError)
   {}
 
   //! Returns point to the next ErrorsPage
@@ -189,6 +191,7 @@ public:
   //! Returns an error message
   Standard_CString ErrorMessage() const { return myError.ToCString(); }
 
+  DEFINE_STANDARD_ALLOC
 private:
 
   ErrorsPage* myNext;              //!< Chaining of records pages
@@ -203,9 +206,9 @@ private:
 StepFile_ReadData::StepFile_ReadData()
   :myMaxChar(50000), myMaxRec(5000), myMaxArg(10000), myModePrint(0),
   myNbRec(0), myNbHead(0), myNbPar(0), myYaRec(0),
-  myNumSub(0), myErrorArg(Standard_False), myResText(NULL), myCurrType(TextValue::SubList),
-  mySubArg(NULL), myTypeArg(Interface_ParamSub), myCurrArg(NULL), myFirstRec(NULL),
-  myCurRec(NULL), myLastRec(NULL), myCurScope(NULL), myFirstError(NULL), myCurError(NULL)
+  myNumSub(0), myErrorArg(Standard_False), myResText(nullptr), myCurrType(TextValue::SubList),
+  mySubArg(nullptr), myTypeArg(Interface_ParamSub), myCurrArg(nullptr), myFirstRec(nullptr),
+  myCurRec(nullptr), myLastRec(nullptr), myCurScope(nullptr), myFirstError(nullptr), myCurError(nullptr)
 {
   myOneCharPage = new CharactersPage(myMaxChar);
   myOneArgPage = new ArgumentsPage(myMaxArg);
@@ -266,7 +269,7 @@ void StepFile_ReadData::RecordNewEntity()
   SetTypeArg(Interface_ParamSub);
   mySubArg = myCurRec->myIdent;
   myCurRec = myCurRec->myNext;
-  myLastRec->myNext = NULL;
+  myLastRec->myNext = nullptr;
 }
 
 //=======================================================================
@@ -278,8 +281,9 @@ void StepFile_ReadData::RecordIdent()
 {
   myCurRec = CreateNewRecord();
   GetResultText(&myCurRec->myIdent);
-  myCurRec->myNext = NULL;
-  myCurRec->myFirst = NULL;
+  myCurRec->myNext = nullptr;
+  myCurRec->myFirst = nullptr;
+  myCurRec->myLast = nullptr;
   myYaRec = 1;
 }
 
@@ -294,8 +298,9 @@ void StepFile_ReadData::RecordType()
   {
     myCurRec = CreateNewRecord();
     myCurRec->myIdent = TextValue::IdZero;
-    myCurRec->myNext = NULL;
-    myCurRec->myFirst = NULL;
+    myCurRec->myNext = nullptr;
+    myCurRec->myFirst = nullptr;
+    myCurRec->myLast = nullptr;
   }
   GetResultText(&myCurRec->myType);
   myYaRec = myNumSub = 0;
@@ -329,7 +334,8 @@ void StepFile_ReadData::RecordListStart()
     aSubRec->myType = myCurrType;
     myCurrType = TextValue::SubList;
     aSubRec->myNext = myCurRec;
-    aSubRec->myFirst = NULL;
+    aSubRec->myFirst = nullptr;
+    aSubRec->myLast = nullptr;
     myCurRec = aSubRec;
   }
   myErrorArg = Standard_False; // Reset error arguments mode
@@ -364,18 +370,23 @@ void StepFile_ReadData::CreateNewArg()
   if (myTypeArg == Interface_ParamMisc)
     myErrorArg = Standard_True;
 
-  if (myCurRec->myFirst == NULL)
+  if (myCurRec->myFirst == nullptr)
   {
     myCurRec->myFirst = aNewArg;
+    myCurRec->myLast = aNewArg;
+  }
+  else if (myCurRec->myLast == nullptr)
+  {
+    myCurRec->myFirst->myNext = aNewArg;
+    myCurRec->myLast = aNewArg;
   }
   else
   {
-    Argument* aNextArg = myCurRec->myFirst;
-    while (aNextArg->myNext != NULL)
-      aNextArg = aNextArg->myNext;
+    Argument* aNextArg = myCurRec->myLast;
     aNextArg->myNext = aNewArg;
+    myCurRec->myLast = aNewArg;
   }
-  aNewArg->myNext = NULL;
+  aNewArg->myNext = nullptr;
 }
 
 //=======================================================================
@@ -395,10 +406,7 @@ void StepFile_ReadData::CreateErrorArg()
     return;
   }
 
-  Argument* aCurrArg = myCurRec->myFirst;
-  while (aCurrArg->myNext != NULL)
-    aCurrArg = aCurrArg->myNext;
-
+  Argument* aCurrArg = myCurRec->myLast;
   GetResultText(&aCurrArg->myValue);
 }
 
@@ -418,7 +426,8 @@ void StepFile_ReadData::AddNewScope()
   aRecord = CreateNewRecord();
   aRecord->myIdent = TextValue::Scope;
   aRecord->myType = TextValue::Nil;
-  aRecord->myFirst = NULL;
+  aRecord->myFirst = nullptr;
+  aRecord->myLast = nullptr;
   AddNewRecord(aRecord);
 }
 
@@ -431,12 +440,13 @@ void StepFile_ReadData::FinalOfScope()
 {
   Scope* anOldScope;
   Record* aRecord;
-  if (myCurScope == NULL) return;
+  if (myCurScope == nullptr) return;
 
   aRecord = CreateNewRecord();
   aRecord->myIdent = TextValue::Scope;
   aRecord->myType = TextValue::Nil;
-  aRecord->myFirst = NULL;
+  aRecord->myFirst = nullptr;
+  aRecord->myLast = nullptr;
 
   if (mySubArg[0] == '$')
   {
@@ -468,18 +478,18 @@ void StepFile_ReadData::ClearRecorder(const Standard_Integer theMode)
 {
   if (theMode & 1)
   {
-    while (myOneRecPage != NULL)
+    while (myOneRecPage != nullptr)
     {
       RecordsPage* aNewPage = myOneRecPage->myNext;
       delete myOneRecPage;
       myOneRecPage = aNewPage;
     }
-    while (myOneArgPage != NULL) {
+    while (myOneArgPage != nullptr) {
       ArgumentsPage* aNewPage = myOneArgPage->myNext;
       delete myOneArgPage;
       myOneArgPage = aNewPage;
     }
-    while (myFirstError != NULL)
+    while (myFirstError != nullptr)
     {
       ErrorsPage* aNewErrorPage = myFirstError->NextErrorPage();
       delete myFirstError;
@@ -488,7 +498,7 @@ void StepFile_ReadData::ClearRecorder(const Standard_Integer theMode)
   }
   if (theMode & 2)
   {
-    while (myOneCharPage != NULL)
+    while (myOneCharPage != nullptr)
     {
       CharactersPage* aNewPage = myOneCharPage->myNext;
       delete myOneCharPage;
@@ -504,7 +514,7 @@ void StepFile_ReadData::ClearRecorder(const Standard_Integer theMode)
 
 Standard_Boolean StepFile_ReadData::GetArgDescription(Interface_ParamType* theType, char** theValue)
 {
-  if (myCurrArg == NULL)
+  if (myCurrArg == nullptr)
     return Standard_False;
   *theType = myCurrArg->myType;
   *theValue = myCurrArg->myValue;
@@ -536,11 +546,11 @@ Standard_Boolean StepFile_ReadData::GetRecordDescription(char** theIdent,
                                                          char** theType,
                                                          int* theNbArg)
 {
-  if (myCurRec == NULL)
+  if (myCurRec == nullptr)
     return Standard_False;
   *theIdent = myCurRec->myIdent;
   *theType = myCurRec->myType;
-  *theNbArg = (myCurRec->myFirst != NULL);
+  *theNbArg = (myCurRec->myFirst != nullptr);
   myCurrArg = myCurRec->myFirst;
   return Standard_True;
 }
@@ -641,7 +651,7 @@ Standard_Integer StepFile_ReadData::GetNbRecord() const
 //=======================================================================
 void StepFile_ReadData::AddError(Standard_CString theErrorMessage)
 {
-  if (myFirstError == NULL)
+  if (myFirstError == nullptr)
   {
     myFirstError = new ErrorsPage(theErrorMessage);
     myCurError = myFirstError;
@@ -659,16 +669,16 @@ void StepFile_ReadData::AddError(Standard_CString theErrorMessage)
 //=======================================================================
 Standard_Boolean StepFile_ReadData::ErrorHandle(const Handle(Interface_Check)& theCheck) const
 {
-  if (myFirstError != NULL)
+  if (myFirstError != nullptr)
   {
     ErrorsPage* aCurrent = myFirstError;
-    while (aCurrent != NULL)
+    while (aCurrent != nullptr)
     {
       theCheck->AddFail(aCurrent->ErrorMessage(), "Undefined Parsing");
       aCurrent = aCurrent->NextErrorPage();
     }
   }
-  return myFirstError == NULL;
+  return myFirstError == nullptr;
 }
 
 //=======================================================================
@@ -677,7 +687,7 @@ Standard_Boolean StepFile_ReadData::ErrorHandle(const Handle(Interface_Check)& t
 //=======================================================================
 Standard_CString StepFile_ReadData::GetLastError() const
 {
-  return myCurError != NULL ? myCurError->ErrorMessage() : NULL;
+  return myCurError != nullptr ? myCurError->ErrorMessage() : nullptr;
 }
 
 //=======================================================================
@@ -714,8 +724,8 @@ void StepFile_ReadData::GetResultText(char** theText)
 void StepFile_ReadData::AddNewRecord(Record* theNewRecord)
 {
   myNbRec++;
-  if (myFirstRec == NULL) myFirstRec = theNewRecord;
-  if (myLastRec != NULL) myLastRec->myNext = theNewRecord;
+  if (myFirstRec == nullptr) myFirstRec = theNewRecord;
+  if (myLastRec != nullptr) myLastRec->myNext = theNewRecord;
   myLastRec = theNewRecord;
 }
 
@@ -750,13 +760,13 @@ void StepFile_ReadData::PrintRecord(Record* theRecord)
   int aNumArg = 0;
   int aNumLen = 0;
   int anArgLen = 0;
-  if (theRecord == NULL) { Printf("Non defini\n"); return; }
+  if (theRecord == nullptr) { Printf("Not defined\n"); return; }
   Printf("Ident : %s  Type : %s  Nb.Arg.s : %s\n",
     theRecord->myIdent, theRecord->myType,
     (theRecord->myFirst ? theRecord->myFirst->myValue : ""));
   if (myModePrint < 2) return;
   myCurrArg = theRecord->myFirst;
-  while (myCurrArg != NULL)
+  while (myCurrArg != nullptr)
   {
     aNumArg++;
     anArgLen = (int)strlen(myCurrArg->myValue) + 18;
index 24d51f0a0a68c742afefeb3c2f1db40aee49e42d..b87ec7705e74649f09307a0af66d9ad2a915a368 100644 (file)
@@ -642,9 +642,11 @@ goto find_rule; \
     8bit                don't fail on 8-bit input characters
     warn                warn about inconsistencies
     nodefault           don't create default echo-all rule
+    noinput             disables the generation of code for reading input from standard input
     noyywrap            don't use yywrap() function
     yyclass             define name of the scanner class
 */
+#define YY_NO_INPUT 1
 
 #include <step.tab.hxx>
 #include "stdio.h"
@@ -655,6 +657,11 @@ goto find_rule; \
 #endif
 #define YY_DECL int step::scanner::lex (step::parser::semantic_type* /*yylval*/)
 
+// Disable checking for eof
+#ifdef  YY_INTERACTIVE
+#undef YY_INTERACTIVE
+#endif
+
 typedef step::parser::token token;
 
 /* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect
index 1f77493f45cbcc347f1c43b89b15a9c9ce26a830..a2a401da51ff010d0b6e247f3b863ae1bbc133d0 100644 (file)
     8bit                don't fail on 8-bit input characters
     warn                warn about inconsistencies
     nodefault           don't create default echo-all rule
+    noinput             disables the generation of code for reading input from standard input
     noyywrap            don't use yywrap() function
     yyclass             define name of the scanner class
 */
 %option c++
 %option 8bit warn nodefault
 %option noyywrap
+%option noinput
 %option yyclass="step::scanner"
 
 %top{
 #endif
 #define YY_DECL int step::scanner::lex (step::parser::semantic_type* /*yylval*/)
 
+// Disable checking for eof
+#ifdef  YY_INTERACTIVE
+#undef YY_INTERACTIVE
+#endif
+#define YY_INTERACTIVE 0
+
 typedef step::parser::token token;
 
 /* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect