]> 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:15 +0000 (06:19 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Tue, 16 Oct 2007 06:19:15 +0000 (06:19 +0000)
ginac/mul.cpp
ginac/power.cpp

index 4e95a638310e313444c45736af5b1d090a8f6076..c4cb2e3b90f72026c02a4b19cfd25c07efe66946 100644 (file)
@@ -994,12 +994,14 @@ bool mul::can_be_further_expanded(const ex & e)
 ex mul::expand(unsigned options) const
 {
        {
 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;
                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
        }
 
        // do not rename indices if the object has no indices at all
index 40ba3376a2af6d17d65cbc73fd992314325fe019..25b1f43a40bcc6a92750a61471a634f5e4883cc8 100644 (file)
@@ -772,12 +772,12 @@ tinfo_t power::return_type_tinfo() const
 
 ex power::expand(unsigned options) 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;
                return *this;
-       
+       }
+
        const ex expanded_basis = basis.expand(options);
        const ex expanded_exponent = exponent.expand(options);
        
        const ex expanded_basis = basis.expand(options);
        const ex expanded_exponent = exponent.expand(options);