From 30d71341985c9817170af992f2ef3be520febc61 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Thu, 28 Mar 2002 00:27:14 +0000 Subject: [PATCH] * expairseq::combine_same_terms_sorted_seq() (expairseq.cpp): make this ugh, ohhh, ahh, more... legible. ;-) --- ginac/expairseq.cpp | 65 +++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index b233fe29..3c5a656b 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -1068,42 +1068,43 @@ void expairseq::canonicalize(void) * instance. */ void expairseq::combine_same_terms_sorted_seq(void) { + if (seq.size()<2) + return; + bool needs_further_processing = false; - - if (seq.size()>1) { - epvector::iterator itin1 = seq.begin(); - epvector::iterator itin2 = itin1+1; - epvector::iterator itout = itin1; - epvector::iterator last = seq.end(); - // must_copy will be set to true the first time some combination is - // possible from then on the sequence has changed and must be compacted - bool must_copy = false; - while (itin2!=last) { - if (itin1->rest.compare(itin2->rest)==0) { - itin1->coeff = ex_to(itin1->coeff). - add_dyn(ex_to(itin2->coeff)); - if (expair_needs_further_processing(itin1)) - needs_further_processing = true; - must_copy = true; - } else { - if (!ex_to(itin1->coeff).is_zero()) { - if (must_copy) - *itout = *itin1; - ++itout; - } - itin1 = itin2; + + epvector::iterator itin1 = seq.begin(); + epvector::iterator itin2 = itin1+1; + epvector::iterator itout = itin1; + epvector::iterator last = seq.end(); + // must_copy will be set to true the first time some combination is + // possible from then on the sequence has changed and must be compacted + bool must_copy = false; + while (itin2!=last) { + if (itin1->rest.compare(itin2->rest)==0) { + itin1->coeff = ex_to(itin1->coeff). + add_dyn(ex_to(itin2->coeff)); + if (expair_needs_further_processing(itin1)) + needs_further_processing = true; + must_copy = true; + } else { + if (!ex_to(itin1->coeff).is_zero()) { + if (must_copy) + *itout = *itin1; + ++itout; } - ++itin2; - } - if (!ex_to(itin1->coeff).is_zero()) { - if (must_copy) - *itout = *itin1; - ++itout; + itin1 = itin2; } - if (itout!=last) - seq.erase(itout,last); + ++itin2; } - + if (!ex_to(itin1->coeff).is_zero()) { + if (must_copy) + *itout = *itin1; + ++itout; + } + if (itout!=last) + seq.erase(itout,last); + if (needs_further_processing) { epvector v = seq; seq.clear(); -- 2.44.0