From 2937d83602f33e587dcfc038869fc101f512b291 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Wed, 24 Jan 2024 10:29:14 -0800 Subject: [PATCH] Speed up mvt_value comparison --- mvt.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/mvt.cpp b/mvt.cpp index b693a717..df4e2906 100644 --- a/mvt.cpp +++ b/mvt.cpp @@ -456,15 +456,34 @@ bool mvt_value::operator<(const mvt_value &o) const { return true; } if (type == o.type) { - if ((type == mvt_string && string_value < o.string_value) || - (type == mvt_float && numeric_value.float_value < o.numeric_value.float_value) || - (type == mvt_double && numeric_value.double_value < o.numeric_value.double_value) || - (type == mvt_int && numeric_value.int_value < o.numeric_value.int_value) || - (type == mvt_uint && numeric_value.uint_value < o.numeric_value.uint_value) || - (type == mvt_sint && numeric_value.sint_value < o.numeric_value.sint_value) || - (type == mvt_bool && numeric_value.bool_value < o.numeric_value.bool_value) || - (type == mvt_null && numeric_value.null_value < o.numeric_value.null_value)) { - return true; + switch (type) { + case mvt_string: + return string_value < o.string_value; + + case mvt_float: + return numeric_value.float_value < o.numeric_value.float_value; + + case mvt_double: + return numeric_value.double_value < o.numeric_value.double_value; + + case mvt_int: + return numeric_value.int_value < o.numeric_value.int_value; + + case mvt_uint: + return numeric_value.uint_value < o.numeric_value.uint_value; + + case mvt_sint: + return numeric_value.sint_value < o.numeric_value.sint_value; + + case mvt_bool: + return numeric_value.bool_value < o.numeric_value.bool_value; + + case mvt_null: + return numeric_value.null_value < o.numeric_value.null_value; + + default: + fprintf(stderr, "mvt_value::operator<<: can't happen\n"); + exit(EXIT_IMPOSSIBLE); } }