]> www.ginac.de Git - ginac.git/blobdiff - ginac/ex.cpp
- implemented object fusion as proposed by Richy
[ginac.git] / ginac / ex.cpp
index e3e54c132d2d8fb27348d56efc457e1fdf6b4ff8..1af7f214efa49d76340d78fe8ae0ac679e179f09 100644 (file)
@@ -242,6 +242,19 @@ void ex::makewriteable()
        GINAC_ASSERT(bp->refcount == 1);
 }
 
+/** Share equal objects between expressions.
+ *  @see ex::compare(const basic &) */
+void ex::share(const ex & other) const
+{
+       if ((bp->flags & status_flags::not_shareable) || (other.bp->flags & status_flags::not_shareable))
+               return;
+
+       if (bp->refcount <= other.bp->refcount)
+               bp = other.bp;
+       else
+               other.bp = bp;
+}
+
 /** Helper function for the ex-from-basic constructor. This is where GiNaC's
  *  automatic evaluator and memory management are implemented.
  *  @see ex::ex(const basic &) */