mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-18 20:26:19 +08:00
Fabric: folly::dynamic was replaced with RawValue in prop-parsing infra
Summary: Our long-term plan is to completely illuminate `jsi::Value`-to-`folly::dynamic` serialization step in prop parsing process improving performance and memory pressure. At the same time, we don't want to introduce a hard dependency in application code to JSI because it exposes direct access to VM and prevents parsing some data that come *NOT* from JSVM. RawValue is an extremely light-weight (hopefully fully optimized-out) abstraction that provides limited JSON-like and C++-idiomatic interface. The current particular implementation is still using `folly::dynamic` inside, but I have fully JSI-powered one which will replace the current one right after we figure out how to deal with folly::dynamic-specific callsites. Or we can implement RawValue in a hybrid manner if a code-size implication of that will be minimal. Reviewed By: JoshuaGross, mdvacca Differential Revision: D13962466 fbshipit-source-id: e848522fd242f21e9e771773f2103f1c1d9d7f21
This commit is contained in:
committed by
Facebook Github Bot
parent
b0c8275369
commit
9842e39019
@@ -36,8 +36,8 @@ inline std::string toString(const EllipsizeMode &ellipsisMode) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, EllipsizeMode &result) {
|
||||
auto string = value.getString();
|
||||
inline void fromRawValue(const RawValue &value, EllipsizeMode &result) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "clip") {
|
||||
result = EllipsizeMode::Clip;
|
||||
return;
|
||||
@@ -57,8 +57,8 @@ inline void fromDynamic(const folly::dynamic &value, EllipsizeMode &result) {
|
||||
abort();
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, FontWeight &result) {
|
||||
auto string = value.asString();
|
||||
inline void fromRawValue(const RawValue &value, FontWeight &result) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "normal") {
|
||||
result = FontWeight::Regular;
|
||||
return;
|
||||
@@ -114,8 +114,8 @@ inline std::string toString(const FontWeight &fontWeight) {
|
||||
return folly::to<std::string>((int)fontWeight);
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, FontStyle &result) {
|
||||
auto string = value.asString();
|
||||
inline void fromRawValue(const RawValue &value, FontStyle &result) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "normal") {
|
||||
result = FontStyle::Normal;
|
||||
return;
|
||||
@@ -142,28 +142,28 @@ inline std::string toString(const FontStyle &fontStyle) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, FontVariant &result) {
|
||||
assert(value.isArray());
|
||||
inline void fromRawValue(const RawValue &value, FontVariant &result) {
|
||||
assert(value.hasType<std::vector<std::string>>());
|
||||
result = FontVariant::Default;
|
||||
for (auto &&item : value) {
|
||||
auto string = item.asString();
|
||||
if (string == "small-caps") {
|
||||
auto items = std::vector<std::string>{value};
|
||||
for (const auto &item : items) {
|
||||
if (item == "small-caps") {
|
||||
result = (FontVariant)((int)result | (int)FontVariant::SmallCaps);
|
||||
continue;
|
||||
}
|
||||
if (string == "oldstyle-nums") {
|
||||
if (item == "oldstyle-nums") {
|
||||
result = (FontVariant)((int)result | (int)FontVariant::OldstyleNums);
|
||||
continue;
|
||||
}
|
||||
if (string == "lining-nums") {
|
||||
if (item == "lining-nums") {
|
||||
result = (FontVariant)((int)result | (int)FontVariant::LiningNums);
|
||||
continue;
|
||||
}
|
||||
if (string == "tabular-nums") {
|
||||
if (item == "tabular-nums") {
|
||||
result = (FontVariant)((int)result | (int)FontVariant::TabularNums);
|
||||
continue;
|
||||
}
|
||||
if (string == "proportional-nums") {
|
||||
if (item == "proportional-nums") {
|
||||
result = (FontVariant)((int)result | (int)FontVariant::ProportionalNums);
|
||||
continue;
|
||||
}
|
||||
@@ -196,8 +196,8 @@ inline std::string toString(const FontVariant &fontVariant) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, TextAlignment &result) {
|
||||
auto string = value.asString();
|
||||
inline void fromRawValue(const RawValue &value, TextAlignment &result) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "natural") {
|
||||
result = TextAlignment::Natural;
|
||||
return;
|
||||
@@ -236,8 +236,8 @@ inline std::string toString(const TextAlignment &textAlignment) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, WritingDirection &result) {
|
||||
auto string = value.asString();
|
||||
inline void fromRawValue(const RawValue &value, WritingDirection &result) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "natural") {
|
||||
result = WritingDirection::Natural;
|
||||
return;
|
||||
@@ -264,10 +264,10 @@ inline std::string toString(const WritingDirection &writingDirection) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void fromDynamic(
|
||||
const folly::dynamic &value,
|
||||
inline void fromRawValue(
|
||||
const RawValue &value,
|
||||
TextDecorationLineType &result) {
|
||||
auto string = value.asString();
|
||||
auto string = (std::string)value;
|
||||
if (string == "none") {
|
||||
result = TextDecorationLineType::None;
|
||||
return;
|
||||
@@ -301,10 +301,10 @@ inline std::string toString(
|
||||
}
|
||||
}
|
||||
|
||||
inline void fromDynamic(
|
||||
const folly::dynamic &value,
|
||||
inline void fromRawValue(
|
||||
const RawValue &value,
|
||||
TextDecorationLineStyle &result) {
|
||||
auto string = value.asString();
|
||||
auto string = (std::string)value;
|
||||
if (string == "single") {
|
||||
result = TextDecorationLineStyle::Single;
|
||||
return;
|
||||
@@ -332,10 +332,10 @@ inline std::string toString(
|
||||
}
|
||||
}
|
||||
|
||||
inline void fromDynamic(
|
||||
const folly::dynamic &value,
|
||||
inline void fromRawValue(
|
||||
const RawValue &value,
|
||||
TextDecorationLinePattern &result) {
|
||||
auto string = value.asString();
|
||||
auto string = (std::string)value;
|
||||
if (string == "solid") {
|
||||
result = TextDecorationLinePattern::Solid;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user