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
This commit is contained in:
Valentin Shergin
2019-06-12 21:35:20 -07:00
committed by Facebook Github Bot
parent 1b4c765099
commit 4a4fabf835
+7 -6
View File
@@ -8,6 +8,7 @@
#pragma once
#include <better/optional.h>
#include <folly/Likely.h>
#include <folly/dynamic.h>
#include <react/core/RawProps.h>
#include <react/graphics/Color.h>
@@ -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<T> convertRawProp(
better::optional<T> 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;
}