From bfaf79c9c6f0ea02656d2dab14f4d74949afe70e Mon Sep 17 00:00:00 2001 From: Lakshman Annadorai Date: Fri, 11 Sep 2020 11:25:43 -0700 Subject: [PATCH] Remove MIN and MAX checking for hidl_enum in UserHalHelper native library. VehiclePropValue enums is not sorted by their values. Thus obtaining MIN and MAX values for this enum is O(N), which is the same as looping through all the values and checking whether a given int32_t is in the enum. Test: Tested with `atest -c android.hardware.automotive.vehicle@2.0-utils-unit-tests`. Bug: 168249409 Change-Id: I296a56e31caa7a5ee69eac49806810f83e46571e (cherry picked from commit b7d50b91eb08c0d321718e3d74e740f3b04b3eac) --- automotive/vehicle/2.0/utils/UserHalHelper.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/automotive/vehicle/2.0/utils/UserHalHelper.cpp b/automotive/vehicle/2.0/utils/UserHalHelper.cpp index fcfe4bf17f..abf59b74e3 100644 --- a/automotive/vehicle/2.0/utils/UserHalHelper.cpp +++ b/automotive/vehicle/2.0/utils/UserHalHelper.cpp @@ -141,11 +141,6 @@ Result parseUserAssociations(const hidl_vec& int32Values, size_t template Result verifyAndCast(int32_t value) { T castValue = static_cast(value); - const auto iter = hidl_enum_range(); - if (castValue < *iter.begin() || castValue > *std::prev(iter.end())) { - return Error() << "Value " << value << " not in range [" << toString(*iter.begin()) << ", " - << toString(*std::prev(iter.end())) << "]"; - } for (const auto& v : hidl_enum_range()) { if (castValue == v) { return castValue;