Files
react-native/ReactCommon/react/renderer/core/RawPropsParser.h
T
Pieter De Baets 4b1c8584e1 Remove size_ field from RawPropsParser
Summary:
`size_` will always match `keys_.size()` so we don't have to keep track of it.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D34391445

fbshipit-source-id: f6c9316c989137425abfb7b3d72b571d08240f34
2022-02-25 04:08:01 -08:00

87 lines
2.2 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and 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 <butter/map.h>
#include <butter/small_vector.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/RawPropsKey.h>
#include <react/renderer/core/RawPropsKeyMap.h>
#include <react/renderer/core/RawPropsPrimitives.h>
#include <react/renderer/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() noexcept {
static_assert(
std::is_base_of<Props, PropsT>::value,
"PropsT must be a descendant of Props");
RawProps emptyRawProps{};
// Create a stub parser context.
// Since this prepares the parser by passing in
// empty props, no prop parsers should actually reference the
// ContextContainer or SurfaceId here.
ContextContainer contextContainer{};
PropsParserContext parserContext{-1, contextContainer};
emptyRawProps.parse(*this, parserContext);
PropsT(parserContext, {}, 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 noexcept;
/*
* Non-generic part of `prepare`.
*/
void postPrepare() noexcept;
/*
* To be used by `RawProps` only.
*/
RawValue const *at(RawProps const &rawProps, RawPropsKey const &key)
const noexcept;
mutable butter::small_vector<RawPropsKey, kNumberOfPropsPerComponentSoftCap>
keys_{};
mutable RawPropsKeyMap nameToIndex_{};
mutable bool ready_{false};
};
} // namespace react
} // namespace facebook