From 3ad002be5f19a530099753a8856d87e26fa331a2 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sun, 27 Sep 2015 16:40:09 +0200 Subject: [PATCH] formula: speedup == and != Allow < and > to work with nullptr as well. * src/ltlast/formula.hh: Here. --- src/ltlast/formula.hh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ltlast/formula.hh b/src/ltlast/formula.hh index 35bedab9f..592754e1a 100644 --- a/src/ltlast/formula.hh +++ b/src/ltlast/formula.hh @@ -684,27 +684,43 @@ namespace spot bool operator<(const formula& other) const noexcept { + if (SPOT_UNLIKELY(!other.ptr_)) + return false; + if (SPOT_UNLIKELY(!ptr_)) + return true; return id() < other.id(); } bool operator<=(const formula& other) const noexcept { + if (SPOT_UNLIKELY(!other.ptr_)) + return !ptr_; + if (SPOT_UNLIKELY(!ptr_)) + return true; return id() <= other.id(); } bool operator>(const formula& other) const noexcept { + if (SPOT_UNLIKELY(!ptr_)) + return false; + if (SPOT_UNLIKELY(!other.ptr_)) + return true; return id() > other.id(); } bool operator>=(const formula& other) const noexcept { + if (SPOT_UNLIKELY(!ptr_)) + return !!other.ptr_; + if (SPOT_UNLIKELY(!other.ptr_)) + return true; return id() >= other.id(); } bool operator==(const formula& other) const noexcept { - return id() == other.id(); + return other.ptr_ == ptr_; } bool operator==(std::nullptr_t) const noexcept @@ -714,7 +730,7 @@ namespace spot bool operator!=(const formula& other) const noexcept { - return id() != other.id(); + return other.ptr_ != ptr_; } bool operator!=(std::nullptr_t) const noexcept @@ -722,6 +738,11 @@ namespace spot return ptr_ != nullptr; } + operator bool() const + { + return ptr_ != nullptr; + } + ///////////////////////// // Forwarded functions // ///////////////////////// @@ -929,11 +950,6 @@ namespace spot static formula sugar_equal(const formula& b, uint8_t min, uint8_t max); - operator bool() const - { - return ptr_ != nullptr; - } - #ifndef SWIG const fnode* to_node_() {