Commit bfe73f89 authored by Shimi Zhang's avatar Shimi Zhang Committed by Commit Bot

input: Use set::find to accelerate the finding process

This CL uses a set::find overload to use the uint32_t type to find
the object to avoid construct another object.

By following the style guide, added a comparator struct.
"For example, if your type doesn't have a natural ordering,
but you want to store it in a std::set, use a custom comparator
rather than overloading <."
https://google.github.io/styleguide/cppguide.html#Operator_Overloading

Bug: None
Change-Id: Ic8b9f51a3b3a50601b1ecfa1ba8039ecf16a22ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358449Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798823}
parent 66a4df0c
...@@ -54,11 +54,6 @@ PassthroughTouchEventQueue::TouchEventWithLatencyInfoAndAckState:: ...@@ -54,11 +54,6 @@ PassthroughTouchEventQueue::TouchEventWithLatencyInfoAndAckState::
: TouchEventWithLatencyInfo(event), : TouchEventWithLatencyInfo(event),
ack_state_(blink::mojom::InputEventResultState::kUnknown) {} ack_state_(blink::mojom::InputEventResultState::kUnknown) {}
bool PassthroughTouchEventQueue::TouchEventWithLatencyInfoAndAckState::
operator<(const TouchEventWithLatencyInfoAndAckState& other) const {
return event.unique_touch_event_id < other.event.unique_touch_event_id;
}
PassthroughTouchEventQueue::PassthroughTouchEventQueue( PassthroughTouchEventQueue::PassthroughTouchEventQueue(
PassthroughTouchEventQueueClient* client, PassthroughTouchEventQueueClient* client,
const Config& config) const Config& config)
...@@ -136,13 +131,7 @@ void PassthroughTouchEventQueue::ProcessTouchAck( ...@@ -136,13 +131,7 @@ void PassthroughTouchEventQueue::ProcessTouchAck(
should_stop_timeout_monitor)) should_stop_timeout_monitor))
return; return;
auto touch_event_iter = outstanding_touches_.begin(); auto touch_event_iter = outstanding_touches_.find(unique_touch_event_id);
while (touch_event_iter != outstanding_touches_.end()) {
if (unique_touch_event_id == touch_event_iter->event.unique_touch_event_id)
break;
++touch_event_iter;
}
if (touch_event_iter == outstanding_touches_.end()) if (touch_event_iter == outstanding_touches_.end())
return; return;
......
...@@ -172,7 +172,6 @@ class CONTENT_EXPORT PassthroughTouchEventQueue { ...@@ -172,7 +172,6 @@ class CONTENT_EXPORT PassthroughTouchEventQueue {
: public TouchEventWithLatencyInfo { : public TouchEventWithLatencyInfo {
public: public:
TouchEventWithLatencyInfoAndAckState(const TouchEventWithLatencyInfo&); TouchEventWithLatencyInfoAndAckState(const TouchEventWithLatencyInfo&);
bool operator<(const TouchEventWithLatencyInfoAndAckState&) const;
blink::mojom::InputEventResultState ack_state() const { return ack_state_; } blink::mojom::InputEventResultState ack_state() const { return ack_state_; }
blink::mojom::InputEventResultSource ack_source() const { blink::mojom::InputEventResultSource ack_source() const {
return ack_source_; return ack_source_;
...@@ -188,6 +187,22 @@ class CONTENT_EXPORT PassthroughTouchEventQueue { ...@@ -188,6 +187,22 @@ class CONTENT_EXPORT PassthroughTouchEventQueue {
blink::mojom::InputEventResultState ack_state_; blink::mojom::InputEventResultState ack_state_;
}; };
struct TouchEventWithLatencyInfoAndAckStateComparator {
using is_transparent = void;
bool operator()(const TouchEventWithLatencyInfoAndAckState& lhs,
const TouchEventWithLatencyInfoAndAckState& rhs) const {
return lhs.event.unique_touch_event_id < rhs.event.unique_touch_event_id;
}
bool operator()(const TouchEventWithLatencyInfoAndAckState& lhs,
const uint32_t rhs) const {
return lhs.event.unique_touch_event_id < rhs;
}
bool operator()(const uint32_t lhs,
const TouchEventWithLatencyInfoAndAckState& rhs) const {
return lhs < rhs.event.unique_touch_event_id;
}
};
// These values are logged to UMA. Entries should not be renumbered and // These values are logged to UMA. Entries should not be renumbered and
// numeric values should never be reused. Please keep in sync with // numeric values should never be reused. Please keep in sync with
// "EventPreFilterResult" in src/tools/metrics/histograms/enums.xml. // "EventPreFilterResult" in src/tools/metrics/histograms/enums.xml.
...@@ -248,7 +263,9 @@ class CONTENT_EXPORT PassthroughTouchEventQueue { ...@@ -248,7 +263,9 @@ class CONTENT_EXPORT PassthroughTouchEventQueue {
// Stores outstanding touches that have been sent to the renderer but have // Stores outstanding touches that have been sent to the renderer but have
// not yet been ack'd by the renderer. The set is explicitly ordered based // not yet been ack'd by the renderer. The set is explicitly ordered based
// on the unique touch event id. // on the unique touch event id.
std::set<TouchEventWithLatencyInfoAndAckState> outstanding_touches_; std::set<TouchEventWithLatencyInfoAndAckState,
TouchEventWithLatencyInfoAndAckStateComparator>
outstanding_touches_;
// Whether we should allow events to bypass normal queue filter rules. // Whether we should allow events to bypass normal queue filter rules.
const bool skip_touch_filter_; const bool skip_touch_filter_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment