From 841b07c666cd03f478e206a934e8393a2db8f703 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 5 Oct 2023 14:52:00 -0700 Subject: input: handle change in std::span::size type The pre-standardized version of std::span in external/libcxx had a ptrdiff_t size, but the finalized std::span has a size_t size instead. Also, the std::span::index_type typedef is renamed to size_type. Use an old-style constructor call to implicitly coerce the size value to the proper type. Insert a cast to avoid a signedness comparison warning. Bug: b/175635923 Test: treehugger Change-Id: I96ccf6d5b54d4118b096f97c901073b4fc2f6f9f Merged-In: I96ccf6d5b54d4118b096f97c901073b4fc2f6f9f --- libs/input/MotionPredictor.cpp | 5 +++-- libs/input/TfLiteMotionPredictor.cpp | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/input/MotionPredictor.cpp b/libs/input/MotionPredictor.cpp index 3037573538..abcca345d3 100644 --- a/libs/input/MotionPredictor.cpp +++ b/libs/input/MotionPredictor.cpp @@ -176,12 +176,13 @@ std::unique_ptr MotionPredictor::predict(nsecs_t timestamp) { int64_t predictionTime = mBuffers->lastTimestamp(); const int64_t futureTime = timestamp + mPredictionTimestampOffsetNanos; - for (int i = 0; i < predictedR.size() && predictionTime <= futureTime; ++i) { + for (size_t i = 0; i < static_cast(predictedR.size()) && predictionTime <= futureTime; + ++i) { const TfLiteMotionPredictorSample::Point point = convertPrediction(axisFrom, axisTo, predictedR[i], predictedPhi[i]); // TODO(b/266747654): Stop predictions if confidence is < some threshold. - ALOGD_IF(isDebug(), "prediction %d: %f, %f", i, point.x, point.y); + ALOGD_IF(isDebug(), "prediction %zu: %f, %f", i, point.x, point.y); PointerCoords coords; coords.clear(); coords.setAxisValue(AMOTION_EVENT_AXIS_X, point.x); diff --git a/libs/input/TfLiteMotionPredictor.cpp b/libs/input/TfLiteMotionPredictor.cpp index 85fa176129..8d10ff56b0 100644 --- a/libs/input/TfLiteMotionPredictor.cpp +++ b/libs/input/TfLiteMotionPredictor.cpp @@ -115,8 +115,7 @@ std::span getTensorBuffer(typename std::conditional::value, tensor->name, TfLiteTypeGetName(tensor->type), TfLiteTypeGetName(type)); LOG_ALWAYS_FATAL_IF(!tensor->data.data); - return {reinterpret_cast(tensor->data.data), - static_cast::index_type>(tensor->bytes / sizeof(T))}; + return std::span(reinterpret_cast(tensor->data.data), tensor->bytes / sizeof(T)); } // Verifies that a tensor exists and has an underlying buffer of type T. -- cgit v1.2.3-59-g8ed1b