mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
6468c0a658
Summary: Changelog: [internal] Prevent unnecessary copy of `RawEvent::eventTarget` which is `shared_ptr` inside `EventQueue::enqueueEvent` by passing in rvalue. Reviewed By: JoshuaGross Differential Revision: D28323219 fbshipit-source-id: 7f62e17df5c4264a15adf58f6142155a76de7aae
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "BatchedEventQueue.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
BatchedEventQueue::BatchedEventQueue(
|
|
EventPipe eventPipe,
|
|
StatePipe statePipe,
|
|
std::unique_ptr<EventBeat> eventBeat)
|
|
: EventQueue(eventPipe, statePipe, std::move(eventBeat)) {}
|
|
|
|
void BatchedEventQueue::onEnqueue() const {
|
|
eventBeat_->request();
|
|
}
|
|
|
|
void BatchedEventQueue::enqueueUniqueEvent(RawEvent &&rawEvent) const {
|
|
{
|
|
std::lock_guard<std::mutex> lock(queueMutex_);
|
|
|
|
auto repeatedEvent = eventQueue_.rend();
|
|
|
|
for (auto it = eventQueue_.rbegin(); it != eventQueue_.rend(); ++it) {
|
|
if (it->type == rawEvent.type &&
|
|
it->eventTarget == rawEvent.eventTarget) {
|
|
repeatedEvent = it;
|
|
break;
|
|
} else if (it->eventTarget == rawEvent.eventTarget) {
|
|
// It is necessary to maintain order of different event types
|
|
// for the same target. If the same target has event types A1, B1
|
|
// in the event queue and event A2 occurs. A1 has to stay in the
|
|
// queue.
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (repeatedEvent == eventQueue_.rend()) {
|
|
eventQueue_.push_back(std::move(rawEvent));
|
|
} else {
|
|
*repeatedEvent = std::move(rawEvent);
|
|
}
|
|
}
|
|
|
|
onEnqueue();
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|