Fabric: Getting rid of many `auto &&`
Summary: @public After reading about move-semantic and rvalue refs I realized that we (I) definitely overuse `auto &&` (aka universal reference) construction. Even if this is harmless, does not look good and idiomatic. Whenever I used that from a semantical point of view I always meant "I need an alias for this" which is actually "read-only reference" which is `const auto &`. This is also fit good to our policy where "everything is const (immutable) by default". Hence I change that to how it should be. Reviewed By: fkgozali Differential Revision: D8475637 fbshipit-source-id: 0a691ededa0e798db8ffa053bff0f400913ab7b8
This commit is contained in:
parent
c674303dfd
commit
eabf29e320
|
@ -30,7 +30,7 @@ static UIActivityIndicatorViewStyle convertActivityIndicatorViewStyle(const Acti
|
|||
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:self.bounds];
|
||||
_activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
auto &&defaultProps = ActivityIndicatorViewProps();
|
||||
const auto &defaultProps = ActivityIndicatorViewProps();
|
||||
|
||||
if (defaultProps.animating) {
|
||||
[_activityIndicatorView startAnimating];
|
||||
|
|
|
@ -26,7 +26,7 @@ using namespace facebook::react;
|
|||
action:@selector(onChange:)
|
||||
forControlEvents:UIControlEventValueChanged];
|
||||
|
||||
auto &&defaultProps = SwitchProps();
|
||||
const auto &defaultProps = SwitchProps();
|
||||
|
||||
_switchView.on = defaultProps.value;
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
|
|||
- (void)_registerTouches:(NSSet<UITouch *> *)touches
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
auto &&activeTouch = CreateTouchWithUITouch(touch, _rootComponentView);
|
||||
auto activeTouch = CreateTouchWithUITouch(touch, _rootComponentView);
|
||||
activeTouch.touch.identifier = _identifierPool.dequeue();
|
||||
_activeTouches.emplace(touch, activeTouch);
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
|
|||
- (void)_unregisterTouches:(NSSet<UITouch *> *)touches
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
auto &&activeTouch = _activeTouches[touch];
|
||||
const auto &activeTouch = _activeTouches[touch];
|
||||
_identifierPool.enqueue(activeTouch.touch.identifier);
|
||||
_activeTouches.erase(touch);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
|
|||
BOOL isEndishEventType = eventType == RCTTouchEventTypeTouchEnd || eventType == RCTTouchEventTypeTouchCancel;
|
||||
|
||||
for (UITouch *touch in touches) {
|
||||
auto &&activeTouch = _activeTouches[touch];
|
||||
const auto &activeTouch = _activeTouches[touch];
|
||||
|
||||
if (!activeTouch.eventEmitter) {
|
||||
continue;
|
||||
|
@ -232,7 +232,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
|
|||
uniqueEventEmitter.insert(activeTouch.eventEmitter);
|
||||
}
|
||||
|
||||
for (auto &&pair : _activeTouches) {
|
||||
for (const auto &pair : _activeTouches) {
|
||||
if (!pair.second.eventEmitter) {
|
||||
continue;
|
||||
}
|
||||
|
@ -247,10 +247,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
|
|||
event.touches.insert(pair.second.touch);
|
||||
}
|
||||
|
||||
for (auto &&eventEmitter : uniqueEventEmitter) {
|
||||
for (const auto &eventEmitter : uniqueEventEmitter) {
|
||||
event.targetTouches.clear();
|
||||
|
||||
for (auto &&pair : _activeTouches) {
|
||||
for (const auto &pair : _activeTouches) {
|
||||
if (pair.second.eventEmitter == eventEmitter) {
|
||||
event.targetTouches.insert(pair.second.touch);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
assert(std::dynamic_pointer_cast<const ConcreteProps>(props));
|
||||
assert(std::dynamic_pointer_cast<const ConcreteEventEmitter>(eventEmitter));
|
||||
|
||||
auto &&shadowNode = std::make_shared<ShadowNodeT>(
|
||||
const auto &shadowNode = std::make_shared<ShadowNodeT>(
|
||||
tag,
|
||||
rootTag,
|
||||
std::static_pointer_cast<const ConcreteProps>(props),
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
) const override {
|
||||
assert(std::dynamic_pointer_cast<const ShadowNodeT>(sourceShadowNode));
|
||||
|
||||
auto &&shadowNode = std::make_shared<ShadowNodeT>(
|
||||
const auto &shadowNode = std::make_shared<ShadowNodeT>(
|
||||
std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode),
|
||||
std::static_pointer_cast<const ConcreteProps>(props),
|
||||
std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter),
|
||||
|
|
|
@ -33,7 +33,7 @@ void EventEmitter::dispatchEvent(
|
|||
const folly::dynamic &payload,
|
||||
const EventPriority &priority
|
||||
) const {
|
||||
auto &&eventDispatcher = eventDispatcher_.lock();
|
||||
const auto &eventDispatcher = eventDispatcher_.lock();
|
||||
if (!eventDispatcher) {
|
||||
return;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void EventEmitter::dispatchEvent(
|
|||
}
|
||||
|
||||
EventTarget EventEmitter::createEventTarget() const {
|
||||
auto &&eventDispatcher = eventDispatcher_.lock();
|
||||
const auto &eventDispatcher = eventDispatcher_.lock();
|
||||
assert(eventDispatcher);
|
||||
return eventDispatcher->createEventTarget(instanceHandle_);
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ inline T convertRawProp(
|
|||
const T &sourceValue,
|
||||
const T &defaultValue = T()
|
||||
) {
|
||||
auto &&iterator = rawProps.find(name);
|
||||
const auto &iterator = rawProps.find(name);
|
||||
if (iterator == rawProps.end()) {
|
||||
return sourceValue;
|
||||
}
|
||||
|
||||
auto &&value = iterator->second;
|
||||
const auto &value = iterator->second;
|
||||
|
||||
// Special case: `null` always means `the prop was removed, use default value`.
|
||||
if (value.isNull()) {
|
||||
|
@ -65,12 +65,12 @@ inline static folly::Optional<T> convertRawProp(
|
|||
const folly::Optional<T> &sourceValue,
|
||||
const folly::Optional<T> &defaultValue = {}
|
||||
) {
|
||||
auto &&iterator = rawProps.find(name);
|
||||
const auto &iterator = rawProps.find(name);
|
||||
if (iterator == rawProps.end()) {
|
||||
return sourceValue;
|
||||
}
|
||||
|
||||
auto &&value = iterator->second;
|
||||
const auto &value = iterator->second;
|
||||
|
||||
// Special case: `null` always means `the prop was removed, use default value`.
|
||||
if (value.isNull()) {
|
||||
|
|
|
@ -22,11 +22,11 @@ void ScrollViewShadowNode::updateLocalData() {
|
|||
ensureUnsealed();
|
||||
|
||||
Rect contentBoundingRect;
|
||||
for (auto &&childNode : getLayoutableChildNodes()) {
|
||||
for (const auto &childNode : getLayoutableChildNodes()) {
|
||||
contentBoundingRect.unionInPlace(childNode->getLayoutMetrics().frame);
|
||||
}
|
||||
|
||||
auto &&localData = std::make_shared<const ScrollViewLocalData>(contentBoundingRect);
|
||||
const auto &localData = std::make_shared<const ScrollViewLocalData>(contentBoundingRect);
|
||||
setLocalData(localData);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ AttributedString BaseTextShadowNode::getAttributedString(
|
|||
|
||||
AttributedString attributedString;
|
||||
|
||||
for (auto &&childNode : *childNodes) {
|
||||
for (const auto &childNode : *childNodes) {
|
||||
// RawShadowNode
|
||||
SharedRawTextShadowNode rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
|
||||
if (rawTextShadowNode) {
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace react {
|
|||
|
||||
Scheduler::Scheduler(const SharedContextContainer &contextContainer):
|
||||
contextContainer_(contextContainer) {
|
||||
auto &&eventDispatcher = std::make_shared<SchedulerEventDispatcher>();
|
||||
auto &&componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer);
|
||||
const auto &eventDispatcher = std::make_shared<SchedulerEventDispatcher>();
|
||||
const auto &componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer);
|
||||
|
||||
uiManager_ = std::make_shared<FabricUIManager>(componentDescriptorRegistry);
|
||||
uiManager_->setDelegate(this);
|
||||
|
@ -40,27 +40,27 @@ Scheduler::~Scheduler() {
|
|||
}
|
||||
|
||||
void Scheduler::registerRootTag(Tag rootTag) {
|
||||
auto &&shadowTree = std::make_shared<ShadowTree>(rootTag);
|
||||
const auto &shadowTree = std::make_shared<ShadowTree>(rootTag);
|
||||
shadowTree->setDelegate(this);
|
||||
shadowTreeRegistry_.insert({rootTag, shadowTree});
|
||||
}
|
||||
|
||||
void Scheduler::unregisterRootTag(Tag rootTag) {
|
||||
auto &&iterator = shadowTreeRegistry_.find(rootTag);
|
||||
auto &&shadowTree = iterator->second;
|
||||
const auto &iterator = shadowTreeRegistry_.find(rootTag);
|
||||
const auto &shadowTree = iterator->second;
|
||||
assert(shadowTree);
|
||||
shadowTree->setDelegate(nullptr);
|
||||
shadowTreeRegistry_.erase(iterator);
|
||||
}
|
||||
|
||||
Size Scheduler::measure(const Tag &rootTag, const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const {
|
||||
auto &&shadowTree = shadowTreeRegistry_.at(rootTag);
|
||||
const auto &shadowTree = shadowTreeRegistry_.at(rootTag);
|
||||
assert(shadowTree);
|
||||
return shadowTree->measure(layoutConstraints, layoutContext);
|
||||
}
|
||||
|
||||
void Scheduler::constraintLayout(const Tag &rootTag, const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) {
|
||||
auto &&shadowTree = shadowTreeRegistry_.at(rootTag);
|
||||
const auto &shadowTree = shadowTreeRegistry_.at(rootTag);
|
||||
assert(shadowTree);
|
||||
return shadowTree->constraintLayout(layoutConstraints, layoutContext);
|
||||
}
|
||||
|
@ -86,8 +86,8 @@ void Scheduler::shadowTreeDidCommit(const SharedShadowTree &shadowTree, const Tr
|
|||
#pragma mark - UIManagerDelegate
|
||||
|
||||
void Scheduler::uiManagerDidFinishTransaction(Tag rootTag, const SharedShadowNodeUnsharedList &rootChildNodes) {
|
||||
auto &&iterator = shadowTreeRegistry_.find(rootTag);
|
||||
auto &&shadowTree = iterator->second;
|
||||
const auto &iterator = shadowTreeRegistry_.find(rootTag);
|
||||
const auto &shadowTree = iterator->second;
|
||||
assert(shadowTree);
|
||||
return shadowTree->complete(rootChildNodes);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace react {
|
|||
ShadowTree::ShadowTree(Tag rootTag):
|
||||
rootTag_(rootTag) {
|
||||
|
||||
auto &&noopEventEmitter = std::make_shared<const ViewEventEmitter>(nullptr, rootTag, nullptr);
|
||||
const auto &noopEventEmitter = std::make_shared<const ViewEventEmitter>(nullptr, rootTag, nullptr);
|
||||
rootShadowNode_ = std::make_shared<RootShadowNode>(
|
||||
rootTag,
|
||||
rootTag,
|
||||
|
@ -50,7 +50,7 @@ void ShadowTree::constraintLayout(const LayoutConstraints &layoutConstraints, co
|
|||
|
||||
UnsharedRootShadowNode ShadowTree::cloneRootShadowNode(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const {
|
||||
auto oldRootShadowNode = rootShadowNode_;
|
||||
auto &&props = std::make_shared<const RootProps>(*oldRootShadowNode->getProps(), layoutConstraints, layoutContext);
|
||||
const auto &props = std::make_shared<const RootProps>(*oldRootShadowNode->getProps(), layoutConstraints, layoutContext);
|
||||
auto newRootShadowNode = std::make_shared<RootShadowNode>(oldRootShadowNode, props, nullptr, nullptr);
|
||||
return newRootShadowNode;
|
||||
}
|
||||
|
@ -99,32 +99,32 @@ bool ShadowTree::commit(const SharedRootShadowNode &newRootShadowNode) {
|
|||
}
|
||||
|
||||
void ShadowTree::emitLayoutEvents(const TreeMutationInstructionList &instructions) {
|
||||
for (auto &&instruction : instructions) {
|
||||
auto &&type = instruction.getType();
|
||||
for (const auto &instruction : instructions) {
|
||||
const auto &type = instruction.getType();
|
||||
|
||||
// Only `Insertion` and `Replacement` instructions can affect layout metrics.
|
||||
if (
|
||||
type == TreeMutationInstruction::Insertion ||
|
||||
type == TreeMutationInstruction::Replacement
|
||||
) {
|
||||
auto &&newShadowNode = instruction.getNewChildNode();
|
||||
auto &&eventEmitter = newShadowNode->getEventEmitter();
|
||||
auto &&viewEventEmitter = std::dynamic_pointer_cast<const ViewEventEmitter>(eventEmitter);
|
||||
const auto &newShadowNode = instruction.getNewChildNode();
|
||||
const auto &eventEmitter = newShadowNode->getEventEmitter();
|
||||
const auto &viewEventEmitter = std::dynamic_pointer_cast<const ViewEventEmitter>(eventEmitter);
|
||||
|
||||
// Checking if particular shadow node supports `onLayout` event (part of `ViewEventEmitter`).
|
||||
if (viewEventEmitter) {
|
||||
// Now we know that both (old and new) shadow nodes must be `LayoutableShadowNode` subclasses.
|
||||
assert(std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode));
|
||||
// TODO(T29661055): Consider using `std::reinterpret_pointer_cast`.
|
||||
auto &&newLayoutableShadowNode =
|
||||
const auto &newLayoutableShadowNode =
|
||||
std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode);
|
||||
|
||||
// In case if we have `oldShadowNode`, we have to check that layout metrics have changed.
|
||||
if (type == TreeMutationInstruction::Replacement) {
|
||||
auto &&oldShadowNode = instruction.getOldChildNode();
|
||||
const auto &oldShadowNode = instruction.getOldChildNode();
|
||||
assert(std::dynamic_pointer_cast<const LayoutableShadowNode>(oldShadowNode));
|
||||
// TODO(T29661055): Consider using `std::reinterpret_pointer_cast`.
|
||||
auto &&oldLayoutableShadowNode =
|
||||
const auto &oldLayoutableShadowNode =
|
||||
std::dynamic_pointer_cast<const LayoutableShadowNode>(oldShadowNode);
|
||||
|
||||
if (oldLayoutableShadowNode->getLayoutMetrics() == newLayoutableShadowNode->getLayoutMetrics()) {
|
||||
|
|
|
@ -131,7 +131,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
auto &&other = static_cast<const ConcreteViewShadowNode&>(rhs);
|
||||
const auto &other = static_cast<const ConcreteViewShadowNode&>(rhs);
|
||||
return getLayoutMetrics() == other.getLayoutMetrics();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ void ViewEventEmitter::onAccessibilityMagicTap() const {
|
|||
|
||||
void ViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
|
||||
folly::dynamic payload = folly::dynamic::object();
|
||||
auto &&frame = layoutMetrics.frame;
|
||||
const auto &frame = layoutMetrics.frame;
|
||||
payload["layout"] = folly::dynamic::object
|
||||
("x", frame.origin.x)
|
||||
("y", frame.origin.y)
|
||||
|
@ -57,7 +57,7 @@ static folly::dynamic touchPayload(const Touch &touch) {
|
|||
|
||||
static folly::dynamic touchesPayload(const Touches &touches) {
|
||||
folly::dynamic array = folly::dynamic::array();
|
||||
for (auto &&touch : touches) {
|
||||
for (const auto &touch : touches) {
|
||||
array.push_back(touchPayload(touch));
|
||||
}
|
||||
return array;
|
||||
|
|
|
@ -42,7 +42,7 @@ ViewProps::ViewProps(const ViewProps &sourceProps, const RawProps &rawProps):
|
|||
#pragma mark - DebugStringConvertible
|
||||
|
||||
SharedDebugStringConvertibleList ViewProps::getDebugProps() const {
|
||||
auto &&defaultViewProps = ViewProps();
|
||||
const auto &defaultViewProps = ViewProps();
|
||||
|
||||
return
|
||||
AccessibilityProps::getDebugProps() +
|
||||
|
|
|
@ -230,11 +230,11 @@ inline void fromDynamic(const folly::dynamic &value, YGFloatOptional &result) {
|
|||
inline void fromDynamic(const folly::dynamic &value, Transform &result) {
|
||||
assert(value.isArray());
|
||||
Transform transformMatrix;
|
||||
for (auto &&tranformConfiguration : value) {
|
||||
for (const auto &tranformConfiguration : value) {
|
||||
assert(tranformConfiguration.isObject());
|
||||
auto pair = *tranformConfiguration.items().begin();
|
||||
auto &&operation = pair.first.asString();
|
||||
auto &¶meters = pair.second;
|
||||
const auto &operation = pair.first.asString();
|
||||
const auto ¶meters = pair.second;
|
||||
|
||||
if (operation == "matrix") {
|
||||
assert(parameters.isArray());
|
||||
|
|
Loading…
Reference in New Issue