]> www.ginac.de Git - ginac.git/blobdiff - ginac/expairseq.cpp
Improve method of setting status_flags::dynallocated.
[ginac.git] / ginac / expairseq.cpp
index 67099f5796395e7d012fb1d4a13484278675e800..84b756f9d762e64721bd612485b8be4622a9706c 100644 (file)
 #include "utils.h"
 #include "hash_seed.h"
 #include "indexed.h"
+#include "compiler.h"
 
 #include <algorithm>
 #include <iostream>
 #include <iterator>
+#include <memory>
 #include <stdexcept>
 #include <string>
 
@@ -244,7 +246,7 @@ ex expairseq::eval(int level) const
 
        epvector evaled = evalchildren(level);
        if (!evaled.empty())
-               return (new expairseq(std::move(evaled), overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
+               return dynallocate<expairseq>(std::move(evaled), overall_coeff).setflag(status_flags::evaluated);
        else
                return this->hold();
 }
@@ -558,7 +560,7 @@ expair expairseq::combine_pair_with_coeff_to_pair(const expair &p,
  *  @see expairseq::split_ex_to_pair() */
 ex expairseq::recombine_pair_to_ex(const expair &p) const
 {
-       return lst(p.rest,p.coeff);
+       return lst{p.rest, p.coeff};
 }
 
 bool expairseq::expair_needs_further_processing(epp it)
@@ -714,8 +716,8 @@ void expairseq::construct_from_2_expairseq(const expairseq &s1,
        }
        
        if (needs_further_processing) {
-               epvector v = seq;
-               seq.clear();
+               // Clear seq and start over.
+               epvector v = std::move(seq);
                construct_from_epvector(std::move(v));
        }
 }
@@ -775,8 +777,8 @@ void expairseq::construct_from_expairseq_ex(const expairseq &s,
        }
 
        if (needs_further_processing) {
-               epvector v = seq;
-               seq.clear();
+               // Clear seq and start over.
+               epvector v = std::move(seq);
                construct_from_epvector(std::move(v));
        }
 }
@@ -963,8 +965,8 @@ void expairseq::combine_same_terms_sorted_seq()
                seq.erase(itout,last);
 
        if (needs_further_processing) {
-               epvector v = seq;
-               seq.clear();
+               // Clear seq and start over.
+               epvector v = std::move(seq);
                construct_from_epvector(std::move(v));
        }
 }
@@ -1053,7 +1055,7 @@ epvector expairseq::expandchildren(unsigned options) const
  *    had to be changed. */
 epvector expairseq::evalchildren(int level) const
 {
-       if (level==1)
+       if (likely(level==1))
                return epvector();  // nothing had to be evaluated
        
        if (level == -max_recursion_level)