// Convert the lists to a map
exmap m;
for (lst::const_iterator its = ls.begin(), itr = lr.begin(); its != ls.end(); ++its, ++itr) {
- m[*its] = *itr;
+ m.insert(std::make_pair(*its, *itr));
// Search for products and powers in the expressions to be substituted
// (for an optimization in expairseq::subs())
if (e.info(info_flags::relation_equal)) {
exmap m;
const ex & s = e.lhs();
- m[s] = e.rhs();
+ m.insert(std::make_pair(s, e.rhs()));
if (is_exactly_a<mul>(s) || is_exactly_a<power>(s))
options |= subs_options::pattern_is_product;
return bp->subs(m, options);
if (!r.info(info_flags::relation_equal))
throw(std::invalid_argument("basic::subs(ex): argument must be a list of equations"));
const ex & s = r.lhs();
- m[s] = r.rhs();
+ m.insert(std::make_pair(s, r.rhs()));
// Search for products and powers in the expressions to be substituted
// (for an optimization in expairseq::subs())
{
GINAC_ASSERT(bp->flags & status_flags::dynallocated);
bp.makewritable();
- GINAC_ASSERT(bp->refcount == 1);
+ GINAC_ASSERT(bp->get_refcount() == 1);
+}
+
+/** Share equal objects between expressions.
+ * @see ex::compare(const basic &) */
+void ex::share(const ex & other) const
+{
+ if ((bp->flags | other.bp->flags) & status_flags::not_shareable)
+ return;
+
+ if (bp->get_refcount() <= other.bp->get_refcount())
+ bp = other.bp;
+ else
+ other.bp = bp;
}
/** Helper function for the ex-from-basic constructor. This is where GiNaC's
// it means that eval() hit case b) above. The original object is
// no longer needed (it evaluated into something different), so we
// delete it (because nobody else will).
- if ((other.refcount==0) && (other.flags & status_flags::dynallocated))
+ if ((other.get_refcount() == 0) && (other.flags & status_flags::dynallocated))
delete &other; // yes, you can apply delete to a const pointer
// We can't return a basic& here because the tmpex is destroyed as
// on the heap.
basic *bp = other.duplicate();
bp->setflag(status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount == 0);
+ GINAC_ASSERT(bp->get_refcount() == 0);
return bp;
}
}
default:
basic *bp = new numeric(i);
bp->setflag(status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount == 0);
+ GINAC_ASSERT(bp->get_refcount() == 0);
return *bp;
}
}
default:
basic *bp = new numeric(i);
bp->setflag(status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount == 0);
+ GINAC_ASSERT(bp->get_refcount() == 0);
return *bp;
}
}
default:
basic *bp = new numeric(i);
bp->setflag(status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount == 0);
+ GINAC_ASSERT(bp->get_refcount() == 0);
return *bp;
}
}
default:
basic *bp = new numeric(i);
bp->setflag(status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount == 0);
+ GINAC_ASSERT(bp->get_refcount() == 0);
return *bp;
}
}
{
basic *bp = new numeric(d);
bp->setflag(status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount == 0);
+ GINAC_ASSERT(bp->get_refcount() == 0);
return *bp;
}