Files
react-native/ReactCommon/fabric/core/primitives/RawPropsParser.h
T
Valentin Shergin 902541e874 Fabric: Fixing a concurrency issue in RawProp parsing infra
Summary:
Previously, we stored `keyIndex_` in a Parser object which is incorrect because it makes the parsing process thread-unsafe (the Parser is shared between parsing processes).

That worked previously most of the time because we never parsed props concurrently but we actually do this in the native animation library.

Reviewed By: yungsters

Differential Revision: D16064557

fbshipit-source-id: 211f4301d0746e0f5126a1dcdd59f1ae9a420aa9
2019-06-28 22:53:45 -07:00

78 lines
1.8 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.
*/
#pragma once
#include <better/map.h>
#include <better/small_vector.h>
#include <react/core/Props.h>
#include <react/core/RawProps.h>
#include <react/core/RawPropsKey.h>
#include <react/core/RawPropsKeyMap.h>
#include <react/core/RawPropsPrimitives.h>
#include <react/core/RawValue.h>
namespace facebook {
namespace react {
/*
* Specialized (to a particular type of Props) parser that provides the most
* efficient access to `RawProps` content.
*/
class RawPropsParser final {
public:
/*
* Default constructor.
* To be used by `ConcreteComponentDescriptor` only.
*/
RawPropsParser() = default;
/*
* To be used by `ConcreteComponentDescriptor` only.
*/
template <typename PropsT>
void prepare() {
static_assert(
std::is_base_of<Props, PropsT>::value,
"PropsT must be a descendant of Props");
RawProps emptyRawProps{};
emptyRawProps.parse(*this);
PropsT({}, emptyRawProps);
postPrepare();
}
private:
friend class ComponentDescriptor;
template <class ShadowNodeT>
friend class ConcreteComponentDescriptor;
friend class RawProps;
/*
* To be used by `RawProps` only.
*/
void preparse(RawProps const &rawProps) const;
/*
* Non-generic part of `prepare`.
*/
void postPrepare();
/*
* To be used by `RawProps` only.
*/
RawValue const *at(RawProps const &rawProps, RawPropsKey const &key) const;
mutable better::small_vector<RawPropsKey, kNumberOfPropsPerComponentSoftCap>
keys_{};
mutable RawPropsKeyMap nameToIndex_{};
mutable int size_{0};
mutable bool ready_{false};
};
} // namespace react
} // namespace facebook