From: Richard Kreckel Date: Sun, 20 Dec 2015 16:50:07 +0000 (+0100) Subject: Hoist typeid(*this) from loops. X-Git-Tag: release_1-7-0~7^2~27 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=640c8980ed3f00e985ffb4810b3c75a9b8106ba9;ds=sidebyside Hoist typeid(*this) from loops. The compilers don't seem to reliably recognize the invariance of this. --- diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 11da7749..f369bddb 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -601,8 +601,9 @@ bool expairseq::can_make_flat(const expair &p) const void expairseq::construct_from_2_ex(const ex &lh, const ex &rh) { - if (typeid(ex_to(lh)) == typeid(*this)) { - if (typeid(ex_to(rh)) == typeid(*this)) { + const std::type_info& typeid_this = typeid(*this); + if (typeid(ex_to(lh)) == typeid_this) { + if (typeid(ex_to(rh)) == typeid_this) { if (is_a(lh) && lh.info(info_flags::has_indices) && rh.info(info_flags::has_indices)) { ex newrh=rename_dummy_indices_uniquely(lh, rh); @@ -617,7 +618,7 @@ void expairseq::construct_from_2_ex(const ex &lh, const ex &rh) construct_from_expairseq_ex(ex_to(lh), rh); return; } - } else if (typeid(ex_to(rh)) == typeid(*this)) { + } else if (typeid(ex_to(rh)) == typeid_this) { construct_from_expairseq_ex(ex_to(rh),lh); return; } @@ -819,9 +820,10 @@ void expairseq::make_flat(const exvector &v) int nexpairseqs = 0; int noperands = 0; bool do_idx_rename = false; - + + const std::type_info& typeid_this = typeid(*this); for (auto & cit : v) { - if (typeid(ex_to(cit)) == typeid(*this)) { + if (typeid(ex_to(cit)) == typeid_this) { ++nexpairseqs; noperands += ex_to(cit).seq.size(); } @@ -836,7 +838,7 @@ void expairseq::make_flat(const exvector &v) // copy elements and split off numerical part make_flat_inserter mf(v, do_idx_rename); for (auto & cit : v) { - if (typeid(ex_to(cit)) == typeid(*this)) { + if (typeid(ex_to(cit)) == typeid_this) { ex newfactor = mf.handle_factor(cit, _ex1); const expairseq &subseqref = ex_to(newfactor); combine_overall_coeff(subseqref.overall_coeff); @@ -863,9 +865,10 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming) int nexpairseqs = 0; int noperands = 0; bool really_need_rename_inds = false; - + + const std::type_info& typeid_this = typeid(*this); for (auto & cit : v) { - if (typeid(ex_to(cit.rest)) == typeid(*this)) { + if (typeid(ex_to(cit.rest)) == typeid_this) { ++nexpairseqs; noperands += ex_to(cit.rest).seq.size(); } @@ -881,7 +884,7 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming) // copy elements and split off numerical part for (auto & cit : v) { - if (typeid(ex_to(cit.rest)) == typeid(*this) && + if (typeid(ex_to(cit.rest)) == typeid_this && this->can_make_flat(cit)) { ex newrest = mf.handle_factor(cit.rest, cit.coeff); const expairseq &subseqref = ex_to(newrest);