mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove unnecessary extra prototype from ReactNativeElement (#49699)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49699 Changelog: [internal] Just a minor optimization in `ReactNativeElement`, to stop creating an unnecessary object in the prototype chain for the `super()` removal optimization. Reviewed By: huntie Differential Revision: D70250804 fbshipit-source-id: 1f8104f8e17f12264326cd715e07877a371f9dc5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bf17ace09a
commit
798f2e47aa
@@ -9238,7 +9238,7 @@ declare export function createReactNativeDocument(
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally src/private/webapis/dom/nodes/ReactNativeElement.js 1`] = `
|
||||
"declare class ReactNativeElementMethods
|
||||
"declare class ReactNativeElement
|
||||
extends ReadOnlyElement
|
||||
implements LegacyHostInstanceMethods
|
||||
{
|
||||
@@ -9264,7 +9264,7 @@ exports[`public API should not change unintentionally src/private/webapis/dom/no
|
||||
): void;
|
||||
setNativeProps(nativeProps: { ... }): void;
|
||||
}
|
||||
declare export default typeof ReactNativeElementMethods;
|
||||
declare export default typeof ReactNativeElement;
|
||||
"
|
||||
`;
|
||||
|
||||
|
||||
+31
-23
@@ -60,7 +60,7 @@ const noop = () => {};
|
||||
// was slower than this method because the engine has to create an object than
|
||||
// we then discard to create a new one.
|
||||
|
||||
class ReactNativeElementMethods
|
||||
class ReactNativeElement
|
||||
extends ReadOnlyElement
|
||||
implements LegacyHostInstanceMethods
|
||||
{
|
||||
@@ -227,28 +227,36 @@ class ReactNativeElementMethods
|
||||
}
|
||||
}
|
||||
|
||||
// Alternative constructor just implemented to provide a better performance than
|
||||
// calling super() in the original class.
|
||||
function ReactNativeElement(
|
||||
this: ReactNativeElementMethods,
|
||||
tag: number,
|
||||
viewConfig: ViewConfig,
|
||||
internalInstanceHandle: InternalInstanceHandle,
|
||||
ownerDocument: ReactNativeDocument,
|
||||
) {
|
||||
// Inlined from `ReadOnlyNode`
|
||||
setOwnerDocument(this, ownerDocument);
|
||||
setInstanceHandle(this, internalInstanceHandle);
|
||||
type ReactNativeElementT = ReactNativeElement;
|
||||
|
||||
this.__nativeTag = tag;
|
||||
this.__internalInstanceHandle = internalInstanceHandle;
|
||||
this.__viewConfig = viewConfig;
|
||||
function replaceConstructorWithoutSuper(
|
||||
ReactNativeElementClass: Class<ReactNativeElementT>,
|
||||
): Class<ReactNativeElementT> {
|
||||
// Alternative constructor just implemented to provide a better performance than
|
||||
// calling super() in the original class.
|
||||
// eslint-disable-next-line no-shadow
|
||||
function ReactNativeElement(
|
||||
this: ReactNativeElementT,
|
||||
tag: number,
|
||||
viewConfig: ViewConfig,
|
||||
internalInstanceHandle: InternalInstanceHandle,
|
||||
ownerDocument: ReactNativeDocument,
|
||||
) {
|
||||
// Inlined from `ReadOnlyNode`
|
||||
setOwnerDocument(this, ownerDocument);
|
||||
setInstanceHandle(this, internalInstanceHandle);
|
||||
|
||||
this.__nativeTag = tag;
|
||||
this.__internalInstanceHandle = internalInstanceHandle;
|
||||
this.__viewConfig = viewConfig;
|
||||
}
|
||||
|
||||
ReactNativeElement.prototype = ReactNativeElementClass.prototype;
|
||||
|
||||
// $FlowExpectedError[incompatible-return]
|
||||
return ReactNativeElement;
|
||||
}
|
||||
|
||||
ReactNativeElement.prototype = Object.create(
|
||||
ReactNativeElementMethods.prototype,
|
||||
);
|
||||
|
||||
// $FlowExpectedError[prop-missing]
|
||||
// $FlowFixMe[incompatible-cast]
|
||||
export default ReactNativeElement as typeof ReactNativeElementMethods;
|
||||
export default replaceConstructorWithoutSuper(
|
||||
ReactNativeElement,
|
||||
) as typeof ReactNativeElement;
|
||||
|
||||
Reference in New Issue
Block a user