From 1e4be91918b614e74a3882132fa4442e758f0e4d Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 24 Jan 2017 13:31:20 -0500 Subject: [PATCH] =?UTF-8?q?mac:=20Faster=20bit=20testing=20for=20EXC=5FGUA?= =?UTF-8?q?RD=20exception=20=E2=80=9Cflavors=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After e7630628e9c9, I thought “isn’t there a standard library function for that?” There is! Change-Id: I284c7fdf8535c4fc53100e80fceb363bf2afee93 Reviewed-on: https://chromium-review.googlesource.com/431856 Reviewed-by: Scott Graham --- util/mach/exception_types.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/util/mach/exception_types.cc b/util/mach/exception_types.cc index 85bdf770..d33fa937 100644 --- a/util/mach/exception_types.cc +++ b/util/mach/exception_types.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "base/logging.h" #include "base/mac/mach_logging.h" @@ -200,16 +201,19 @@ int32_t ExceptionCodeForMetrics(exception_type_t exception, // one another. For the purposes of encoding these codes for metrics, // convert the flavor codes to their corresponding bit shift values. const uint32_t guard_flavor = (code_0 >> 32) & 0x1fffffff; - uint8_t metrics_guard_flavor = 0xff; - for (int bit = 0; bit < 29; ++bit) { - const uint32_t test_mask = 1 << bit; - if (guard_flavor & test_mask) { - // Make sure that no other bits are set. - DCHECK_EQ(guard_flavor, test_mask); + const int first_bit = ffs(guard_flavor); + uint8_t metrics_guard_flavor; + if (first_bit) { + metrics_guard_flavor = first_bit - 1; - metrics_guard_flavor = bit; - break; + const uint32_t test_guard_flavor = 1 << metrics_guard_flavor; + if (guard_flavor != test_guard_flavor) { + // Another bit is set. + DCHECK_EQ(guard_flavor, test_guard_flavor); + metrics_guard_flavor = 0xff; } + } else { + metrics_guard_flavor = 0xff; } metrics_code_0 = (guard_type << 8) | metrics_guard_flavor;