1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0033350: Data Exchange, Step Import - Improving parsing performance

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.
This commit is contained in:
dpasukhi 2023-03-22 18:22:44 +00:00 committed by vglukhik
parent e84e862fc1
commit 636743f90c
3 changed files with 77 additions and 52 deletions

View File

@ -35,20 +35,21 @@ class StepFile_ReadData::CharactersPage {
public: public:
CharactersPage(const Standard_Integer theMaxCar) :myNext(NULL), myUsed(0) CharactersPage(const Standard_Integer theMaxCar) :myNext(nullptr), myUsed(0)
{ {
myCharacters = new char[theMaxCar]; myCharacters = new char[theMaxCar];
} }
~CharactersPage() ~CharactersPage()
{ {
if (myCharacters != NULL) if (myCharacters != nullptr)
{ {
delete[] myCharacters; delete[] myCharacters;
myCharacters = NULL; myCharacters = nullptr;
} }
} }
DEFINE_STANDARD_ALLOC
public: public:
CharactersPage* myNext; //!< Chaining of character pages CharactersPage* myNext; //!< Chaining of character pages
@ -64,7 +65,7 @@ public:
public: public:
Argument() :myNext(NULL), myValue(NULL), myType(Interface_ParamSub) {} Argument() :myNext(nullptr), myValue(nullptr), myType(Interface_ParamSub) {}
~Argument() {} ~Argument() {}
@ -83,7 +84,7 @@ public:
public: public:
ArgumentsPage(Standard_Integer theMaxArg) :myNext(NULL), myUsed(0) ArgumentsPage(Standard_Integer theMaxArg) :myNext(nullptr), myUsed(0)
{ {
myArgs = new Argument[theMaxArg]; myArgs = new Argument[theMaxArg];
} }
@ -91,7 +92,7 @@ public:
~ArgumentsPage() ~ArgumentsPage()
{ {
delete[] myArgs; delete[] myArgs;
myArgs = NULL; myArgs = nullptr;
} }
public: public:
@ -109,7 +110,7 @@ public:
public: public:
Record() :myNext(NULL), myFirst(NULL), myIdent(NULL), myType(NULL) {} Record() :myNext(nullptr), myFirst(nullptr), myLast(nullptr), myIdent(nullptr), myType(nullptr) {}
~Record() {} ~Record() {}
@ -117,6 +118,7 @@ public:
Record* myNext; //!< Next record in the list Record* myNext; //!< Next record in the list
Argument* myFirst; //!< First argument in the record Argument* myFirst; //!< First argument in the record
Argument* myLast; //!< Last argument in the record
char* myIdent; //!< Record identifier (Example: "#12345") or scope-end char* myIdent; //!< Record identifier (Example: "#12345") or scope-end
char* myType; //!< Type of the record char* myType; //!< Type of the record
}; };
@ -129,14 +131,14 @@ public:
public: public:
Scope() :myPrevious(NULL), myRecord(NULL) {} Scope() :myPrevious(nullptr), myRecord(nullptr) {}
~Scope() ~Scope()
{ {
if (myRecord != NULL) if (myRecord != nullptr)
{ {
delete[] myRecord; delete[] myRecord;
myRecord = NULL; myRecord = nullptr;
} }
} }
@ -151,20 +153,20 @@ class StepFile_ReadData::RecordsPage
public: public:
RecordsPage(const Standard_Integer theMaxRec) :myNext(NULL), myUsed(0) RecordsPage(const Standard_Integer theMaxRec) :myNext(nullptr), myUsed(0)
{ {
myRecords = new Record[theMaxRec]; myRecords = new Record[theMaxRec];
} }
~RecordsPage() ~RecordsPage()
{ {
if (myRecords != NULL) if (myRecords != nullptr)
{ {
delete[] myRecords; delete[] myRecords;
myRecords = NULL; myRecords = nullptr;
} }
} }
DEFINE_STANDARD_ALLOC
public: public:
RecordsPage* myNext; //!< Chaining of records pages RecordsPage* myNext; //!< Chaining of records pages
@ -177,7 +179,7 @@ class StepFile_ReadData::ErrorsPage
public: public:
ErrorsPage(Standard_CString theError) :myNext(NULL), myError(theError) ErrorsPage(Standard_CString theError) :myNext(nullptr), myError(theError)
{} {}
//! Returns point to the next ErrorsPage //! Returns point to the next ErrorsPage
@ -189,6 +191,7 @@ public:
//! Returns an error message //! Returns an error message
Standard_CString ErrorMessage() const { return myError.ToCString(); } Standard_CString ErrorMessage() const { return myError.ToCString(); }
DEFINE_STANDARD_ALLOC
private: private:
ErrorsPage* myNext; //!< Chaining of records pages ErrorsPage* myNext; //!< Chaining of records pages
@ -203,9 +206,9 @@ private:
StepFile_ReadData::StepFile_ReadData() StepFile_ReadData::StepFile_ReadData()
:myMaxChar(50000), myMaxRec(5000), myMaxArg(10000), myModePrint(0), :myMaxChar(50000), myMaxRec(5000), myMaxArg(10000), myModePrint(0),
myNbRec(0), myNbHead(0), myNbPar(0), myYaRec(0), myNbRec(0), myNbHead(0), myNbPar(0), myYaRec(0),
myNumSub(0), myErrorArg(Standard_False), myResText(NULL), myCurrType(TextValue::SubList), myNumSub(0), myErrorArg(Standard_False), myResText(nullptr), myCurrType(TextValue::SubList),
mySubArg(NULL), myTypeArg(Interface_ParamSub), myCurrArg(NULL), myFirstRec(NULL), mySubArg(nullptr), myTypeArg(Interface_ParamSub), myCurrArg(nullptr), myFirstRec(nullptr),
myCurRec(NULL), myLastRec(NULL), myCurScope(NULL), myFirstError(NULL), myCurError(NULL) myCurRec(nullptr), myLastRec(nullptr), myCurScope(nullptr), myFirstError(nullptr), myCurError(nullptr)
{ {
myOneCharPage = new CharactersPage(myMaxChar); myOneCharPage = new CharactersPage(myMaxChar);
myOneArgPage = new ArgumentsPage(myMaxArg); myOneArgPage = new ArgumentsPage(myMaxArg);
@ -266,7 +269,7 @@ void StepFile_ReadData::RecordNewEntity()
SetTypeArg(Interface_ParamSub); SetTypeArg(Interface_ParamSub);
mySubArg = myCurRec->myIdent; mySubArg = myCurRec->myIdent;
myCurRec = myCurRec->myNext; myCurRec = myCurRec->myNext;
myLastRec->myNext = NULL; myLastRec->myNext = nullptr;
} }
//======================================================================= //=======================================================================
@ -278,8 +281,9 @@ void StepFile_ReadData::RecordIdent()
{ {
myCurRec = CreateNewRecord(); myCurRec = CreateNewRecord();
GetResultText(&myCurRec->myIdent); GetResultText(&myCurRec->myIdent);
myCurRec->myNext = NULL; myCurRec->myNext = nullptr;
myCurRec->myFirst = NULL; myCurRec->myFirst = nullptr;
myCurRec->myLast = nullptr;
myYaRec = 1; myYaRec = 1;
} }
@ -294,8 +298,9 @@ void StepFile_ReadData::RecordType()
{ {
myCurRec = CreateNewRecord(); myCurRec = CreateNewRecord();
myCurRec->myIdent = TextValue::IdZero; myCurRec->myIdent = TextValue::IdZero;
myCurRec->myNext = NULL; myCurRec->myNext = nullptr;
myCurRec->myFirst = NULL; myCurRec->myFirst = nullptr;
myCurRec->myLast = nullptr;
} }
GetResultText(&myCurRec->myType); GetResultText(&myCurRec->myType);
myYaRec = myNumSub = 0; myYaRec = myNumSub = 0;
@ -329,7 +334,8 @@ void StepFile_ReadData::RecordListStart()
aSubRec->myType = myCurrType; aSubRec->myType = myCurrType;
myCurrType = TextValue::SubList; myCurrType = TextValue::SubList;
aSubRec->myNext = myCurRec; aSubRec->myNext = myCurRec;
aSubRec->myFirst = NULL; aSubRec->myFirst = nullptr;
aSubRec->myLast = nullptr;
myCurRec = aSubRec; myCurRec = aSubRec;
} }
myErrorArg = Standard_False; // Reset error arguments mode myErrorArg = Standard_False; // Reset error arguments mode
@ -364,18 +370,23 @@ void StepFile_ReadData::CreateNewArg()
if (myTypeArg == Interface_ParamMisc) if (myTypeArg == Interface_ParamMisc)
myErrorArg = Standard_True; myErrorArg = Standard_True;
if (myCurRec->myFirst == NULL) if (myCurRec->myFirst == nullptr)
{ {
myCurRec->myFirst = aNewArg; myCurRec->myFirst = aNewArg;
myCurRec->myLast = aNewArg;
}
else if (myCurRec->myLast == nullptr)
{
myCurRec->myFirst->myNext = aNewArg;
myCurRec->myLast = aNewArg;
} }
else else
{ {
Argument* aNextArg = myCurRec->myFirst; Argument* aNextArg = myCurRec->myLast;
while (aNextArg->myNext != NULL)
aNextArg = aNextArg->myNext;
aNextArg->myNext = aNewArg; aNextArg->myNext = aNewArg;
myCurRec->myLast = aNewArg;
} }
aNewArg->myNext = NULL; aNewArg->myNext = nullptr;
} }
//======================================================================= //=======================================================================
@ -395,10 +406,7 @@ void StepFile_ReadData::CreateErrorArg()
return; return;
} }
Argument* aCurrArg = myCurRec->myFirst; Argument* aCurrArg = myCurRec->myLast;
while (aCurrArg->myNext != NULL)
aCurrArg = aCurrArg->myNext;
GetResultText(&aCurrArg->myValue); GetResultText(&aCurrArg->myValue);
} }
@ -418,7 +426,8 @@ void StepFile_ReadData::AddNewScope()
aRecord = CreateNewRecord(); aRecord = CreateNewRecord();
aRecord->myIdent = TextValue::Scope; aRecord->myIdent = TextValue::Scope;
aRecord->myType = TextValue::Nil; aRecord->myType = TextValue::Nil;
aRecord->myFirst = NULL; aRecord->myFirst = nullptr;
aRecord->myLast = nullptr;
AddNewRecord(aRecord); AddNewRecord(aRecord);
} }
@ -431,12 +440,13 @@ void StepFile_ReadData::FinalOfScope()
{ {
Scope* anOldScope; Scope* anOldScope;
Record* aRecord; Record* aRecord;
if (myCurScope == NULL) return; if (myCurScope == nullptr) return;
aRecord = CreateNewRecord(); aRecord = CreateNewRecord();
aRecord->myIdent = TextValue::Scope; aRecord->myIdent = TextValue::Scope;
aRecord->myType = TextValue::Nil; aRecord->myType = TextValue::Nil;
aRecord->myFirst = NULL; aRecord->myFirst = nullptr;
aRecord->myLast = nullptr;
if (mySubArg[0] == '$') if (mySubArg[0] == '$')
{ {
@ -468,18 +478,18 @@ void StepFile_ReadData::ClearRecorder(const Standard_Integer theMode)
{ {
if (theMode & 1) if (theMode & 1)
{ {
while (myOneRecPage != NULL) while (myOneRecPage != nullptr)
{ {
RecordsPage* aNewPage = myOneRecPage->myNext; RecordsPage* aNewPage = myOneRecPage->myNext;
delete myOneRecPage; delete myOneRecPage;
myOneRecPage = aNewPage; myOneRecPage = aNewPage;
} }
while (myOneArgPage != NULL) { while (myOneArgPage != nullptr) {
ArgumentsPage* aNewPage = myOneArgPage->myNext; ArgumentsPage* aNewPage = myOneArgPage->myNext;
delete myOneArgPage; delete myOneArgPage;
myOneArgPage = aNewPage; myOneArgPage = aNewPage;
} }
while (myFirstError != NULL) while (myFirstError != nullptr)
{ {
ErrorsPage* aNewErrorPage = myFirstError->NextErrorPage(); ErrorsPage* aNewErrorPage = myFirstError->NextErrorPage();
delete myFirstError; delete myFirstError;
@ -488,7 +498,7 @@ void StepFile_ReadData::ClearRecorder(const Standard_Integer theMode)
} }
if (theMode & 2) if (theMode & 2)
{ {
while (myOneCharPage != NULL) while (myOneCharPage != nullptr)
{ {
CharactersPage* aNewPage = myOneCharPage->myNext; CharactersPage* aNewPage = myOneCharPage->myNext;
delete myOneCharPage; delete myOneCharPage;
@ -504,7 +514,7 @@ void StepFile_ReadData::ClearRecorder(const Standard_Integer theMode)
Standard_Boolean StepFile_ReadData::GetArgDescription(Interface_ParamType* theType, char** theValue) Standard_Boolean StepFile_ReadData::GetArgDescription(Interface_ParamType* theType, char** theValue)
{ {
if (myCurrArg == NULL) if (myCurrArg == nullptr)
return Standard_False; return Standard_False;
*theType = myCurrArg->myType; *theType = myCurrArg->myType;
*theValue = myCurrArg->myValue; *theValue = myCurrArg->myValue;
@ -536,11 +546,11 @@ Standard_Boolean StepFile_ReadData::GetRecordDescription(char** theIdent,
char** theType, char** theType,
int* theNbArg) int* theNbArg)
{ {
if (myCurRec == NULL) if (myCurRec == nullptr)
return Standard_False; return Standard_False;
*theIdent = myCurRec->myIdent; *theIdent = myCurRec->myIdent;
*theType = myCurRec->myType; *theType = myCurRec->myType;
*theNbArg = (myCurRec->myFirst != NULL); *theNbArg = (myCurRec->myFirst != nullptr);
myCurrArg = myCurRec->myFirst; myCurrArg = myCurRec->myFirst;
return Standard_True; return Standard_True;
} }
@ -641,7 +651,7 @@ Standard_Integer StepFile_ReadData::GetNbRecord() const
//======================================================================= //=======================================================================
void StepFile_ReadData::AddError(Standard_CString theErrorMessage) void StepFile_ReadData::AddError(Standard_CString theErrorMessage)
{ {
if (myFirstError == NULL) if (myFirstError == nullptr)
{ {
myFirstError = new ErrorsPage(theErrorMessage); myFirstError = new ErrorsPage(theErrorMessage);
myCurError = myFirstError; myCurError = myFirstError;
@ -659,16 +669,16 @@ void StepFile_ReadData::AddError(Standard_CString theErrorMessage)
//======================================================================= //=======================================================================
Standard_Boolean StepFile_ReadData::ErrorHandle(const Handle(Interface_Check)& theCheck) const Standard_Boolean StepFile_ReadData::ErrorHandle(const Handle(Interface_Check)& theCheck) const
{ {
if (myFirstError != NULL) if (myFirstError != nullptr)
{ {
ErrorsPage* aCurrent = myFirstError; ErrorsPage* aCurrent = myFirstError;
while (aCurrent != NULL) while (aCurrent != nullptr)
{ {
theCheck->AddFail(aCurrent->ErrorMessage(), "Undefined Parsing"); theCheck->AddFail(aCurrent->ErrorMessage(), "Undefined Parsing");
aCurrent = aCurrent->NextErrorPage(); 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 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) void StepFile_ReadData::AddNewRecord(Record* theNewRecord)
{ {
myNbRec++; myNbRec++;
if (myFirstRec == NULL) myFirstRec = theNewRecord; if (myFirstRec == nullptr) myFirstRec = theNewRecord;
if (myLastRec != NULL) myLastRec->myNext = theNewRecord; if (myLastRec != nullptr) myLastRec->myNext = theNewRecord;
myLastRec = theNewRecord; myLastRec = theNewRecord;
} }
@ -750,13 +760,13 @@ void StepFile_ReadData::PrintRecord(Record* theRecord)
int aNumArg = 0; int aNumArg = 0;
int aNumLen = 0; int aNumLen = 0;
int anArgLen = 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", Printf("Ident : %s Type : %s Nb.Arg.s : %s\n",
theRecord->myIdent, theRecord->myType, theRecord->myIdent, theRecord->myType,
(theRecord->myFirst ? theRecord->myFirst->myValue : "")); (theRecord->myFirst ? theRecord->myFirst->myValue : ""));
if (myModePrint < 2) return; if (myModePrint < 2) return;
myCurrArg = theRecord->myFirst; myCurrArg = theRecord->myFirst;
while (myCurrArg != NULL) while (myCurrArg != nullptr)
{ {
aNumArg++; aNumArg++;
anArgLen = (int)strlen(myCurrArg->myValue) + 18; anArgLen = (int)strlen(myCurrArg->myValue) + 18;

View File

@ -642,9 +642,11 @@ goto find_rule; \
8bit don't fail on 8-bit input characters 8bit don't fail on 8-bit input characters
warn warn about inconsistencies warn warn about inconsistencies
nodefault don't create default echo-all rule 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 noyywrap don't use yywrap() function
yyclass define name of the scanner class yyclass define name of the scanner class
*/ */
#define YY_NO_INPUT 1
#include <step.tab.hxx> #include <step.tab.hxx>
#include "stdio.h" #include "stdio.h"
@ -655,6 +657,11 @@ goto find_rule; \
#endif #endif
#define YY_DECL int step::scanner::lex (step::parser::semantic_type* /*yylval*/) #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; typedef step::parser::token token;
/* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect /* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect

View File

@ -18,12 +18,14 @@
8bit don't fail on 8-bit input characters 8bit don't fail on 8-bit input characters
warn warn about inconsistencies warn warn about inconsistencies
nodefault don't create default echo-all rule 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 noyywrap don't use yywrap() function
yyclass define name of the scanner class yyclass define name of the scanner class
*/ */
%option c++ %option c++
%option 8bit warn nodefault %option 8bit warn nodefault
%option noyywrap %option noyywrap
%option noinput
%option yyclass="step::scanner" %option yyclass="step::scanner"
%top{ %top{
@ -46,6 +48,12 @@
#endif #endif
#define YY_DECL int step::scanner::lex (step::parser::semantic_type* /*yylval*/) #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; typedef step::parser::token token;
/* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect /* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect