From b34cb090c5a5e05a51bd436bb06f5c57bd790c30 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Fri, 4 May 2001 23:29:42 +0000 Subject: [PATCH] * 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. --- ginac/add.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 -- 2.44.0