Use RingBuffer in VelocityTracker
Several strategies used to store data points in an array design to work
as a circular buffer. Now that we've the RingBuffer data structure,
migrate to using that.
Bug: 267211645
Test: atest libinput_tests
Change-Id: Id1253c646c81d3c30baea496b2e3a75f5726c616
diff --git a/include/input/RingBuffer.h b/include/input/RingBuffer.h
index 67984b7..5e9972e 100644
--- a/include/input/RingBuffer.h
+++ b/include/input/RingBuffer.h
@@ -24,7 +24,6 @@
#include <type_traits>
#include <utility>
-#include <android-base/logging.h>
#include <android-base/stringprintf.h>
namespace android {
@@ -272,15 +271,16 @@
// Converts the index of an element in [0, size()] to its corresponding index in mBuffer.
size_type bufferIndex(size_type elementIndex) const {
- CHECK_LE(elementIndex, size());
+ if (elementIndex > size()) {
+ abort();
+ }
size_type index = mBegin + elementIndex;
if (index >= capacity()) {
index -= capacity();
}
- CHECK_LT(index, capacity())
- << android::base::StringPrintf("Invalid index calculated for element (%zu) "
- "in buffer of size %zu",
- elementIndex, size());
+ if (index >= capacity()) {
+ abort();
+ }
return index;
}
diff --git a/include/input/VelocityTracker.h b/include/input/VelocityTracker.h
index 6d51515..6d1de64 100644
--- a/include/input/VelocityTracker.h
+++ b/include/input/VelocityTracker.h
@@ -17,6 +17,7 @@
#pragma once
#include <input/Input.h>
+#include <input/RingBuffer.h>
#include <utils/BitSet.h>
#include <utils/Timers.h>
#include <map>
@@ -172,8 +173,7 @@
// protected const field.
static constexpr uint32_t HISTORY_SIZE = 20;
- std::map<int32_t /*pointerId*/, size_t /*positionInArray*/> mIndex;
- std::map<int32_t /*pointerId*/, std::array<Movement, HISTORY_SIZE>> mMovements;
+ std::map<int32_t /*pointerId*/, RingBuffer<Movement>> mMovements;
};
/*