]> www.ginac.de Git - ginac.git/commitdiff
* basic::compare(const basic&): Rearrange in a more compact fashion.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Wed, 10 Apr 2002 20:05:34 +0000 (20:05 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Wed, 10 Apr 2002 20:05:34 +0000 (20:05 +0000)
  (Rationale: produces better code.)

ginac/basic.cpp

index 26ec8667e55ea0a217053b826dc40f1ae2ab5cf1..d4f06fe8017ff0668803f75d5293fa54a187062f 100644 (file)
@@ -712,48 +712,35 @@ ex basic::subs(const ex & e, bool no_pattern) const
  *  1 greater. */
 int basic::compare(const basic & other) const
 {
-       unsigned hash_this = gethash();
-       unsigned hash_other = other.gethash();
-       
+       const unsigned hash_this = gethash();
+       const unsigned hash_other = other.gethash();
        if (hash_this<hash_other) return -1;
        if (hash_this>hash_other) return 1;
-       
-       unsigned typeid_this = tinfo();
-       unsigned typeid_other = other.tinfo();
-       
-       if (typeid_this<typeid_other) {
-//             std::cout << "hash collision, different types: " 
-//                       << *this << " and " << other << std::endl;
-//             this->print(print_tree(std::cout));
-//             std::cout << " and ";
-//             other.print(print_tree(std::cout));
-//             std::cout << std::endl;
-               return -1;
-       }
-       if (typeid_this>typeid_other) {
-//             std::cout << "hash collision, different types: " 
-//                       << *this << " and " << other << std::endl;
-//             this->print(print_tree(std::cout));
-//             std::cout << " and ";
-//             other.print(print_tree(std::cout));
-//             std::cout << std::endl;
-               return 1;
+
+       const unsigned typeid_this = tinfo();
+       const unsigned typeid_other = other.tinfo();
+       if (typeid_this==typeid_other) {
+               GINAC_ASSERT(typeid(*this)==typeid(other));
+//             int cmpval = compare_same_type(other);
+//             if ((cmpval!=0) && (hash_this<0x80000000U)) {
+//                     std::cout << "hash collision, same type: " 
+//                               << *this << " and " << other << std::endl;
+//                     this->print(print_tree(std::cout));
+//                     std::cout << " and ";
+//                     other.print(print_tree(std::cout));
+//                     std::cout << std::endl;
+//             }
+//             return cmpval;
+               return compare_same_type(other);
+       } else {
+//                     std::cout << "hash collision, different types: " 
+//                               << *this << " and " << other << std::endl;
+//                     this->print(print_tree(std::cout));
+//                     std::cout << " and ";
+//                     other.print(print_tree(std::cout));
+//                     std::cout << std::endl;
+               return (typeid_this<typeid_other ? -1 : 1);
        }
-       
-       GINAC_ASSERT(typeid(*this)==typeid(other));
-       
-//     int cmpval = compare_same_type(other);
-//     if ((cmpval!=0) && (hash_this<0x80000000U)) {
-//             std::cout << "hash collision, same type: " 
-//                       << *this << " and " << other << std::endl;
-//             this->print(print_tree(std::cout));
-//             std::cout << " and ";
-//             other.print(print_tree(std::cout));
-//             std::cout << std::endl;
-//     }
-//     return cmpval;
-       
-       return compare_same_type(other);
 }
 
 /** Test for equality.