From: Richard Kreckel Date: Fri, 4 May 2001 23:29:42 +0000 (+0000) Subject: * add::coeff(): don't epvector::reserve() more terms than we'll actually X-Git-Tag: release_0-8-3~27 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=b34cb090c5a5e05a51bd436bb06f5c57bd790c30 * add::coeff(): don't epvector::reserve() more terms than we'll actually need and don't epvector::push_back() all those _ex0()'s into coeffseq. --- diff --git a/ginac/add.cpp b/ginac/add.cpp index 1b7b2719..412bd5a5 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -284,18 +284,16 @@ int add::ldegree(const ex & s) const ex add::coeff(const ex & s, int n) const { epvector coeffseq; - coeffseq.reserve(seq.size()); - + epvector::const_iterator it=seq.begin(); while (it!=seq.end()) { - coeffseq.push_back(combine_ex_with_coeff_to_pair((*it).rest.coeff(s,n), - (*it).coeff)); + ex restcoeff = it->rest.coeff(s,n); + if (!restcoeff.is_zero()) + coeffseq.push_back(combine_ex_with_coeff_to_pair(restcoeff,it->coeff)); ++it; } - if (n==0) { - return (new add(coeffseq,overall_coeff))->setflag(status_flags::dynallocated); - } - return (new add(coeffseq))->setflag(status_flags::dynallocated); + + return (new add(coeffseq, n==0 ? overall_coeff : default_overall_coeff()))->setflag(status_flags::dynallocated); } ex add::eval(int level) const