@@ -40,7 +40,7 @@ std::streampos sectionReader::findNormalString( const std::string& str, bool sem
4040 }
4141 if ( c == ' \' ' ) {
4242 // push past string
43- _file.putback ( c );
43+ _file.unget ( );
4444 ToExpressStr ( _file, _lazyFile->getInstMgr ()->getErrorDesc () );
4545 }
4646 if ( ( c == ' /' ) && ( _file.peek () == ' *' ) ) {
@@ -101,10 +101,46 @@ std::string * sectionReader::getDelimitedKeyword( const char * delimiters ) {
101101}
102102
103103std::streampos sectionReader::seekInstanceEnd () {
104- // TODO do it without findNormalString(), counting parenthesis and looking for ");" outside of a comment/string
105- // should we use our own string parsing function? could be faster if it doesn't need to store the data...
106- // or modify the existing one?
107- return findNormalString ( " )" , true );
104+ char c;
105+ int parenDepth;
106+ while ( c = _file.get (), _file.good () ) {
107+ switch ( c ) {
108+ case ' (' :
109+ parenDepth++;
110+ break ;
111+ case ' /' :
112+ if ( _file.peek () == ' *' ) {
113+ findNormalString ( " */" );
114+ } else {
115+ return -1 ;
116+ }
117+ break ;
118+ case ' \' ' :
119+ _file.unget ();
120+ ToExpressStr ( _file, _lazyFile->getInstMgr ()->getErrorDesc () );
121+ break ;
122+ case ' =' :
123+ return -1 ;
124+ case ' #' :
125+ // TODO record references
126+ break ;
127+ case ' )' :
128+ if ( --parenDepth == 0 ) {
129+ skipWS ();
130+ if ( _file.get () == ' ;' ) {
131+ return _file.tellg ();
132+ } else {
133+ _file.unget ();
134+ }
135+ }
136+ default :
137+ break ;
138+ }
139+ }
140+ return -1 ;
141+ // NOTE - old way: return findNormalString( ")", true );
142+ // old memory consumption: 673728kb; User CPU time: 35480ms; System CPU time: 17710ms (with 266MB catia-ferrari-sharknose.stp)
143+ // new memory: 673340kb; User CPU time: 29890ms; System CPU time: 11650ms
108144}
109145
110146void sectionReader::locateAllInstances () {
@@ -157,8 +193,8 @@ instanceID sectionReader::readInstanceNumber() {
157193
158194// TODO: most of the rest of readdata1, all of readdata2
159195SDAI_Application_instance * sectionReader::getRealInstance ( lazyInstanceLoc* inst ) {
160- // assert( inst->instance == -1 );
161- std::cerr << " getRealInstance() isn't implemented. Instance #" << inst->instance << std::endl;
196+ // assert( inst->instance < 4 );
197+ std::cerr << " getRealInstance() isn't implemented. Instance #" << inst->instance << std::endl;
162198 return 0 ;
163199}
164200
0 commit comments