From b097c3729d98c6f61febcac833aae4837090f37d Mon Sep 17 00:00:00 2001 From: ngb Date: Wed, 25 Nov 2026 00:47:07 +0530 Subject: [PATCH] GH-55757 : [C++] Simplify DispacthBool in FloatingEqualityDispatcher --- cpp/src/arrow/compare.cc | 48 ++++++++++------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/cpp/src/arrow/compare.cc b/cpp/src/arrow/compare.cc index 06f1d14e73a3..735acb10869c 100644 --- a/cpp/src/arrow/compare.cc +++ b/cpp/src/arrow/compare.cc @@ -57,6 +57,7 @@ #include "arrow/util/unreachable.h" #include "arrow/visit_scalar_inline.h" #include "arrow/visit_type_inline.h" +#include "arrow/csv/lexing_internal.h" namespace arrow { @@ -147,51 +148,26 @@ struct FloatingEquality { const int32_t ulp_distance; }; + template struct FloatingEqualityDispatcher { const EqualOptions& options; Visitor&& visit; - template - void DispatchL4() { - if (options.ulp_distance()) { - visit(FloatingEquality< - T, FloatingEqualityFlags>{ - options}); - } else { - visit(FloatingEquality< - T, FloatingEqualityFlags>{ - options}); - } - } - - template - void DispatchL3() { - if (options.signed_zeros_equal()) { - DispatchL4(); - } else { - DispatchL4(); - } - } - - template - void DispatchL2() { - if (options.nans_equal()) { - DispatchL3(); - } else { - DispatchL3(); - } - } - void Dispatch() { - if (options.atol()) { - DispatchL2(); - } else { - DispatchL2(); - } + csv::internal::DispatchBool( + [&]() { + visit(FloatingEquality< + T, FloatingEqualityFlags>{options}); + }, + options.atol().has_value(), options.nans_equal(), + options.signed_zeros_equal(), options.ulp_distance().has_value()); } }; + // Call `visit(equality_func)` where `equality_func` has the signature `bool(T, T)` // and returns true if the two values compare equal. template