summaryrefslogtreecommitdiff
path: root/libs/input
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-11-26 18:46:45 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-11-26 18:46:45 +0000
commitb09cb2b40994e1a64cd3cbdfd47df88e53edcc15 (patch)
tree2e6be59c602dbb44696c01232a7de40dd7f40c71 /libs/input
parent226685c51a00010c3e63a6cc42a13877f7d67f4d (diff)
parent727a44e37ee5ac778fc3abf0fcd849847f5d7c29 (diff)
Merge "Use queue and unique_ptr for pooled events"
Diffstat (limited to 'libs/input')
-rw-r--r--libs/input/Input.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 34b305e548..c7303efd13 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -595,43 +595,37 @@ PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) :
}
PooledInputEventFactory::~PooledInputEventFactory() {
- for (size_t i = 0; i < mKeyEventPool.size(); i++) {
- delete mKeyEventPool.itemAt(i);
- }
- for (size_t i = 0; i < mMotionEventPool.size(); i++) {
- delete mMotionEventPool.itemAt(i);
- }
}
KeyEvent* PooledInputEventFactory::createKeyEvent() {
- if (!mKeyEventPool.isEmpty()) {
- KeyEvent* event = mKeyEventPool.top();
- mKeyEventPool.pop();
- return event;
+ if (mKeyEventPool.empty()) {
+ return new KeyEvent();
}
- return new KeyEvent();
+ KeyEvent* event = mKeyEventPool.front().release();
+ mKeyEventPool.pop();
+ return event;
}
MotionEvent* PooledInputEventFactory::createMotionEvent() {
- if (!mMotionEventPool.isEmpty()) {
- MotionEvent* event = mMotionEventPool.top();
- mMotionEventPool.pop();
- return event;
+ if (mMotionEventPool.empty()) {
+ return new MotionEvent();
}
- return new MotionEvent();
+ MotionEvent* event = mMotionEventPool.front().release();
+ mMotionEventPool.pop();
+ return event;
}
void PooledInputEventFactory::recycle(InputEvent* event) {
switch (event->getType()) {
case AINPUT_EVENT_TYPE_KEY:
if (mKeyEventPool.size() < mMaxPoolSize) {
- mKeyEventPool.push(static_cast<KeyEvent*>(event));
+ mKeyEventPool.push(std::unique_ptr<KeyEvent>(static_cast<KeyEvent*>(event)));
return;
}
break;
case AINPUT_EVENT_TYPE_MOTION:
if (mMotionEventPool.size() < mMaxPoolSize) {
- mMotionEventPool.push(static_cast<MotionEvent*>(event));
+ mMotionEventPool.push(std::unique_ptr<MotionEvent>(static_cast<MotionEvent*>(event)));
return;
}
break;