]> www.ginac.de Git - ginac.git/commitdiff
inlined ex::swap() and provided versions of iter_swap() for ex and expair
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 27 Mar 2002 21:24:32 +0000 (21:24 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 27 Mar 2002 21:24:32 +0000 (21:24 +0000)
objects to make the STL sorting algorithms a little more efficient

ginac/ex.cpp
ginac/ex.h
ginac/expair.h

index b22ceef802be608c3f110796ee6ac09d56060ee3..c41abee74b5131ea157c9b0b27d842016caddd5c 100644 (file)
@@ -48,19 +48,6 @@ namespace GiNaC {
 
 // public
        
-/** Efficiently swap the contents of two expressions. */
-void ex::swap(ex & other)
-{
-       GINAC_ASSERT(bp!=0);
-       GINAC_ASSERT(bp->flags & status_flags::dynallocated);
-       GINAC_ASSERT(other.bp!=0);
-       GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
-       
-       basic * tmpbp = bp;
-       bp = other.bp;
-       other.bp = tmpbp;
-}
-
 /** Print expression to stream. The formatting of the output is determined
  *  by the kind of print_context object that is passed. Possible formattings
  *  include ginsh-parsable output (the default), tree-like output for
index 0aa96ebc0382f69fb92b9e11fbaad9990147c7a7..f59cd7aea21b5486a3aee142067b0350d3487467 100644 (file)
@@ -97,7 +97,19 @@ public:
        
        // non-virtual functions in this class
 public:
-       void swap(ex & other);
+       /** Efficiently swap the contents of two expressions. */
+       void swap(ex & other)
+       {
+               GINAC_ASSERT(bp!=0);
+               GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+               GINAC_ASSERT(other.bp!=0);
+               GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
+       
+               basic * tmpbp = bp;
+               bp = other.bp;
+               other.bp = tmpbp;
+       }
+
        void print(const print_context & c, unsigned level = 0) const;
        void printtree(std::ostream & os) const;
        void dbgprint(void) const;
@@ -457,6 +469,10 @@ inline bool is_zero(const ex & thisex)
 inline void swap(ex & e1, ex & e2)
 { e1.swap(e2); }
 
+// This makes STL algorithms use the more efficient swap operation for ex objects
+inline void iter_swap(std::vector<ex>::iterator i1, std::vector<ex>::iterator i2)
+{ i1->swap(*i2); }
+
 
 /* Function objects for STL sort() etc. */
 struct ex_is_less : public std::binary_function<ex, ex, bool> {
index 954442509e40a52cc1f7f370c977368db6e28a79..925db97230ea8f471416b27ccedfe9a1328f6925 100644 (file)
@@ -111,6 +111,13 @@ struct expair_swap : public std::binary_function<expair, expair, void> {
        void operator()(expair &lh, expair &rh) const { lh.swap(rh); }
 };
 
+inline void swap(expair & e1, expair & e2)
+{ e1.swap(e2); }
+
+// This makes STL algorithms use the more efficient swap operation for ex objects
+inline void iter_swap(std::vector<expair>::iterator i1, std::vector<expair>::iterator i2)
+{ i1->swap(*i2); }
+
 } // namespace GiNaC
 
 #endif // ndef __GINAC_EXPAIR_H__