Commit f0ac6ddd authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Smaller implementation of to_ordering

Summary:
[Folly] Smaller implementation of `to_ordering`.

Shorter source code, shorter bytecode, no branches/conditionals.

Reviewed By: Orvid

Differential Revision: D9733375

fbshipit-source-id: a2b2a8263b5de2264d3068a424419d63e5b27228
parent 13d4eb3c
...@@ -22,7 +22,7 @@ enum class ordering : int { lt = -1, eq = 0, gt = 1 }; ...@@ -22,7 +22,7 @@ enum class ordering : int { lt = -1, eq = 0, gt = 1 };
template <typename T> template <typename T>
constexpr ordering to_ordering(T c) { constexpr ordering to_ordering(T c) {
return c < T(0) ? ordering::lt : c > T(0) ? ordering::gt : ordering::eq; return ordering(int(c < T(0)) * -1 + int(c > T(0)));
} }
namespace detail { namespace detail {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment