From: Jens Vollinga Date: Wed, 21 Nov 2007 03:22:06 +0000 (+0000) Subject: Synced to HEAD: X-Git-Tag: release_1-4-1~12 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=commitdiff_plain;h=405ed7a5122936707c059154020c58572538d781;p=ginac.git Synced to HEAD: * Fix optimization opportunities missed by Alexei's patch. --- diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 4e95a638..c4cb2e3b 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -994,12 +994,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(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 diff --git a/ginac/power.cpp b/ginac/power.cpp index 7d909e85..9ff79095 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -771,12 +771,12 @@ tinfo_t power::return_type_tinfo() const ex power::expand(unsigned options) const { - if (is_a(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(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);