@@ -147,46 +147,21 @@ int MutableTerm::compare(const MutableTerm &other,
147147  return  0 ;
148148}
149149
150- // / Find the start of \p other in this term, returning end() if
151- // / \p other does not occur as a subterm of this term.
152- decltype (MutableTerm::Symbols)::const_iterator
153- MutableTerm::findSubTerm(Term other) const  {
154-   if  (other.size () > size ())
155-     return  end ();
156- 
157-   return  std::search (begin (), end (), other.begin (), other.end ());
158- }
159- 
160- // / Non-const variant of the above.
161- decltype (MutableTerm::Symbols)::iterator
162- MutableTerm::findSubTerm(Term other) {
163-   if  (other.size () > size ())
164-     return  end ();
165- 
166-   return  std::search (begin (), end (), other.begin (), other.end ());
167- }
168- 
169- // / Replace the first occurrence of \p lhs in this term with
170- // / \p rhs. Note that \p rhs must precede \p lhs in the linear
171- // / order on terms. Returns true if the term contained \p lhs;
172- // / otherwise returns false, in which case the term remains
173- // / unchanged.
174- bool  MutableTerm::rewriteSubTerm (Term lhs, Term rhs) {
175-   //  Find the start of lhs in this term.
176-   auto  found = findSubTerm (lhs);
177- 
178-   //  This term cannot be reduced using this rule.
179-   if  (found == end ())
180-     return  false ;
181- 
150+ // / Replace the subterm in the range [from,to) with \p rhs.
151+ // /
152+ // / Note that \p rhs must precede [from,to) in the linear
153+ // / order on terms.
154+ void  MutableTerm::rewriteSubTerm (
155+     decltype (MutableTerm::Symbols)::iterator from,
156+     decltype(MutableTerm::Symbols)::iterator to,
157+     Term rhs) {
182158  auto  oldSize = size ();
183- 
184-   assert (rhs.size () <= lhs. size () );
159+    unsigned  lhsLength = ( unsigned )(to - from); 
160+   assert (rhs.size () <= lhsLength );
185161
186162  //  Overwrite the occurrence of the left hand side with the
187163  //  right hand side.
188-   auto  newIter = std::copy (rhs.begin (), rhs.end (), found);
189-   auto  oldIter = found + lhs.size ();
164+   auto  newIter = std::copy (rhs.begin (), rhs.end (), from);
190165
191166  //  If the right hand side is shorter than the left hand side,
192167  //  then newIter will point to a location before oldIter, eg
@@ -199,16 +174,15 @@ bool MutableTerm::rewriteSubTerm(Term lhs, Term rhs) {
199174  // 
200175  //  Shift everything over to close the gap (by one location,
201176  //  in this case).
202-   if  (newIter != oldIter ) {
203-     auto  newEnd = std::copy (oldIter , end (), newIter);
177+   if  (newIter != to ) {
178+     auto  newEnd = std::copy (to , end (), newIter);
204179
205180    //  Now, we've moved the gap to the end of the term; close
206181    //  it by shortening the term.
207182    Symbols.erase (newEnd, end ());
208183  }
209184
210-   assert (size () == oldSize - lhs.size () + rhs.size ());
211-   return  true ;
185+   assert (size () == oldSize - lhsLength + rhs.size ());
212186}
213187
214188void  MutableTerm::dump (llvm::raw_ostream &out) const  {
0 commit comments