From 4a4fabf835a155b2a6d590fe69124fc31485e276 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 12 Jun 2019 21:31:30 -0700 Subject: [PATCH] Fabric: `LIKELY/UNLIKELY` annotations in props convertion infra Summary: In theory, those annotations can help the compiler to emit more optimized code and/or code that suggest CPU the proper way to utilize the instruction pipeline after the coming branch. TBH, it's not clear how exactly beneficial those annotations are (esp. on target architectures) but they certainly don't hurt (in all cases here the favorite code branch is obvious). Reviewed By: mdvacca Differential Revision: D15752969 fbshipit-source-id: 8adf25a48107ffde828f735fb1386b30dbe63ede --- ReactCommon/fabric/core/propsConversions.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ReactCommon/fabric/core/propsConversions.h b/ReactCommon/fabric/core/propsConversions.h index 6ed2d795adb..1835a3dfb4f 100644 --- a/ReactCommon/fabric/core/propsConversions.h +++ b/ReactCommon/fabric/core/propsConversions.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -53,15 +54,15 @@ T convertRawProp( U const &defaultValue = U(), char const *namePrefix = nullptr, char const *nameSuffix = nullptr) { - const auto rawValue = rawProps.at(name, namePrefix, nameSuffix); + const auto *rawValue = rawProps.at(name, namePrefix, nameSuffix); - if (!rawValue) { + if (LIKELY(rawValue == nullptr)) { return sourceValue; } // Special case: `null` always means "the prop was removed, use default // value". - if (!rawValue->hasValue()) { + if (UNLIKELY(!rawValue->hasValue())) { return defaultValue; } @@ -78,15 +79,15 @@ static better::optional convertRawProp( better::optional const &defaultValue = {}, char const *namePrefix = nullptr, char const *nameSuffix = nullptr) { - const auto rawValue = rawProps.at(name, namePrefix, nameSuffix); + const auto *rawValue = rawProps.at(name, namePrefix, nameSuffix); - if (!rawValue) { + if (LIKELY(rawValue == nullptr)) { return sourceValue; } // Special case: `null` always means `the prop was removed, use default // value`. - if (!rawValue->hasValue()) { + if (UNLIKELY(!rawValue->hasValue())) { return defaultValue; }