@@ -37,8 +37,6 @@ CHole& CHole::operator=( const CHole& hole )
3737
3838CLeftPartCompiler::CLeftPartCompiler () :
3939 top ( 0 ),
40- left ( 0 ),
41- right ( 0 ),
4240 maxTableSize ( 0 ),
4341 hole ( 0 )
4442{
@@ -111,19 +109,17 @@ void CLeftPartCompiler::splitIntoClasses(CHole* const holes)
111109void CLeftPartCompiler::CompileLeftPart ( CUnitList& leftPart,
112110 bool isRightDirection )
113111{
114- left = 0 ;
115- right = 1 ;
116112 top = 2 ;
117- holes.Append ( CHole ( leftPart, left, right ) );
113+ holes.Append ( CHole ( leftPart, 0 /* left */ , 1 /* right */ ) );
114+ lastUsedHole = holes.GetFirst ();
118115
119116 while ( true ) {
120117 hole = holes.GetFirst ();
121118
122119 while ( hole != 0 ) {
123- CUnitNode* left = hole->GetFirst ();
124- CUnitNode* right = hole->GetLast ();
125-
126- if ( left != right && isFreeVE ( left ) && isFreeVE ( right ) ) {
120+ if ( hole->GetFirst () != hole->GetLast ()
121+ && isFreeVE ( hole->GetFirst () ) && isFreeVE ( hole->GetLast () ) )
122+ {
127123 hole = hole->Next ();
128124 } else {
129125 matchElement ();
@@ -146,6 +142,10 @@ void CLeftPartCompiler::CompileLeftPart( CUnitList& leftPart,
146142
147143void CLeftPartCompiler::removeHole ()
148144{
145+ if ( lastUsedHole == hole ) {
146+ lastUsedHole = 0 ;
147+ }
148+
149149 CHoleNode* nextHole = hole->Next ();
150150 holes.Remove ( hole );
151151 hole = nextHole;
@@ -180,14 +180,19 @@ void CLeftPartCompiler::matchDuplicateVariable(
180180
181181void CLeftPartCompiler::checkBorders ()
182182{
183- if ( left != hole->GetLeft () ) {
184- left = hole->GetLeft ();
185- COperationsBuilder::AddSetLeftBorder ( left );
186- }
187- if ( right != hole->GetRight () ) {
188- right = hole->GetRight ();
189- COperationsBuilder::AddSetRightBorder ( right );
183+ assert ( hole != 0 );
184+ if ( hole != lastUsedHole ) {
185+ if ( lastUsedHole != 0 ) {
186+ COperationsBuilder::AddSaveLeftRight ();
187+ lastUsedHole->SetLeft ( top );
188+ top++;
189+ lastUsedHole->SetRight ( top );
190+ top++;
191+ }
192+ COperationsBuilder::AddSetLeftBorder ( hole->GetLeft () );
193+ COperationsBuilder::AddSetRightBorder ( hole->GetRight () );
190194 }
195+ lastUsedHole = hole;
191196}
192197
193198void CLeftPartCompiler::matchVE (const bool isRightDirection)
@@ -387,16 +392,9 @@ void CLeftPartCompiler::matchLeftParens()
387392
388393 hole->RemoveFirst ();
389394 hole->RemoveLast ();
390-
391- TTableIndex oldRight = right;
392- left = top;
393- top++;
394- right = top;
395- top++;
396- hole->SetLeft ( left );
397- hole->SetRight ( right );
398-
399- holes.InsertAfter ( hole, CHole ( newHole, right, oldRight ) );
395+
396+ holes.InsertAfter ( hole, CHole ( newHole, top, top + 1 ) );
397+ top += 2 ;
400398}
401399
402400void CLeftPartCompiler::matchRightParens ()
@@ -417,16 +415,9 @@ void CLeftPartCompiler::matchRightParens()
417415
418416 hole->RemoveFirst ();
419417 hole->RemoveLast ();
420-
421- TTableIndex oldLeft = left;
422- left = top;
423- top++;
424- right = top;
425- top++;
426- hole->SetLeft ( left );
427- hole->SetRight ( right );
428-
429- holes.InsertBefore ( hole, CHole ( newHole, oldLeft, left ) );
418+
419+ holes.InsertBefore ( hole, CHole ( newHole, top, top + 1 ) );
420+ top += 2 ;
430421}
431422
432423void CLeftPartCompiler::matchLeftSymbol ()
0 commit comments