]> www.ginac.de Git - ginac.git/commitdiff
* Fix optimization opportunities missed by Alexei's patch.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Tue, 16 Oct 2007 06:19:31 +0000 (06:19 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Tue, 16 Oct 2007 06:19:31 +0000 (06:19 +0000)
ginac/mul.cpp
ginac/power.cpp

index b7e0e827bb040189d8915987f3162437d245cbd5..99d811f4762f2e6b703795f73278eeb2cdfebf7c 100644 (file)
@@ -942,12 +942,14 @@ bool mul::can_be_further_expanded(const ex & e)
 ex mul::expand(unsigned options) const
 {
        {
-       // trivial case: expanding the monomial (~ 30% of all calls)
+       // trivial case: expanding the monomial (~ 30% of all calls)
                epvector::const_iterator i = seq.begin(), seq_end = seq.end();
                while ((i != seq.end()) &&  is_a<symbol>(i->rest) && i->coeff.info(info_flags::integer))
                        ++i;
-               if (i == seq_end)
-                       return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+               if (i == seq_end) {
+                       setflag(status_flags::expanded);
+                       return *this;
+               }
        }
 
        // do not rename indices if the object has no indices at all
index 42e14c189352ef7513bac62f69db3da0e682a2b2..e839220d28243208105abacfbe7dbc6f13d57a55 100644 (file)
@@ -680,12 +680,12 @@ unsigned power::return_type_tinfo() const
 
 ex power::expand(unsigned options) const
 {
-       if (is_a<symbol>(basis) && exponent.info(info_flags::integer))
-               return (new power(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
-
-       if (options == 0 && (flags & status_flags::expanded))
+       if (is_a<symbol>(basis) && exponent.info(info_flags::integer)) {
+               // A special case worth optimizing.
+               setflag(status_flags::expanded);
                return *this;
-       
+       }
+
        const ex expanded_basis = basis.expand(options);
        const ex expanded_exponent = exponent.expand(options);