Fabric: Using `const &` type for `ShadowNodeFragment`'s fields
Summary: @public To avoid unnecessary copying of `shared_ptr`s inside ShadowNodeFragment, now we store them as `const &` references. Reviewed By: mdvacca Differential Revision: D8988388 fbshipit-source-id: 0b3582e57ce7577b8fa819392bf33f34e1a60b59
This commit is contained in:
parent
06e62440d3
commit
3770d4df45
|
@ -14,6 +14,7 @@
|
|||
#include <fabric/core/ConcreteShadowNode.h>
|
||||
#include <fabric/core/LayoutableShadowNode.h>
|
||||
#include <fabric/core/ShadowNode.h>
|
||||
#include <fabric/core/ShadowNodeFragment.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
|
||||
namespace facebook {
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <fabric/core/ComponentDescriptor.h>
|
||||
#include <fabric/core/Props.h>
|
||||
#include <fabric/core/ShadowNode.h>
|
||||
#include <fabric/core/ShadowNodeFragment.h>
|
||||
#include <fabric/events/EventDispatcher.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <fabric/core/ShadowNodeFragment.h>
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
#include <fabric/debug/debugStringConvertibleUtils.h>
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
struct ShadowNodeFragment;
|
||||
|
||||
class ShadowNode;
|
||||
|
||||
using SharedShadowNode = std::shared_ptr<const ShadowNode>;
|
||||
|
@ -29,15 +31,6 @@ using SharedShadowNodeList = std::vector<std::shared_ptr<const ShadowNode>>;
|
|||
using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
|
||||
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;
|
||||
|
||||
struct ShadowNodeFragment {
|
||||
Tag tag;
|
||||
Tag rootTag;
|
||||
SharedProps props;
|
||||
SharedEventEmitter eventEmitter;
|
||||
SharedShadowNodeSharedList children;
|
||||
SharedLocalData localData;
|
||||
};
|
||||
|
||||
using ShadowNodeCloneFunction = std::function<UnsharedShadowNode(
|
||||
const SharedShadowNode &sourceShadowNode,
|
||||
const ShadowNodeFragment &fragment
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "ShadowNodeFragment.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
SharedProps &ShadowNodeFragment::nullSharedProps() {
|
||||
static auto &instance = *new SharedProps();
|
||||
return instance;
|
||||
}
|
||||
|
||||
SharedEventEmitter &ShadowNodeFragment::nullSharedEventEmitter() {
|
||||
static auto &instance = *new SharedEventEmitter();
|
||||
return instance;
|
||||
}
|
||||
|
||||
SharedShadowNodeSharedList &ShadowNodeFragment::nullSharedChildren() {
|
||||
static auto &instance = *new SharedShadowNodeSharedList();
|
||||
return instance;
|
||||
}
|
||||
|
||||
SharedLocalData &ShadowNodeFragment::nullLocalData() {
|
||||
static auto &instance = *new SharedLocalData();
|
||||
return instance;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fabric/core/LocalData.h>
|
||||
#include <fabric/core/Props.h>
|
||||
#include <fabric/core/ReactPrimitives.h>
|
||||
#include <fabric/core/ShadowNode.h>
|
||||
#include <fabric/events/EventEmitter.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* An object which supposed to be used as a parameter specifying a shape
|
||||
* of created or cloned ShadowNode.
|
||||
* Note: Most of the fields are `const &` references (essentially just raw
|
||||
* pointers) which means that the Fragment does not copy/store them or
|
||||
* retain ownership of them.
|
||||
*/
|
||||
struct ShadowNodeFragment {
|
||||
Tag tag = 0;
|
||||
Tag rootTag = 0;
|
||||
const SharedProps &props = nullSharedProps();
|
||||
const SharedEventEmitter &eventEmitter = nullSharedEventEmitter();
|
||||
const SharedShadowNodeSharedList &children = nullSharedChildren();
|
||||
const SharedLocalData &localData = nullLocalData();
|
||||
|
||||
private:
|
||||
static SharedProps &nullSharedProps();
|
||||
static SharedEventEmitter &nullSharedEventEmitter();
|
||||
static SharedShadowNodeSharedList &nullSharedChildren();
|
||||
static SharedLocalData &nullLocalData();
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -14,6 +14,7 @@
|
|||
#include <fabric/components/view/ViewShadowNode.h>
|
||||
#include <fabric/core/componentDescriptor.h>
|
||||
#include <fabric/core/LayoutContext.h>
|
||||
#include <fabric/core/ShadowNodeFragment.h>
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue