Skip to content

Commit

Permalink
use c++20 likely and unlikely (#41149)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #41149

changelog: [internal]

RN now builds with C++ 20 and we can move away from folly::Likely.

More about [[likely]] and [[unlikely]] https://en.cppreference.com/w/cpp/language/attributes/likely

Reviewed By: cipolleschi

Differential Revision: D50540008

fbshipit-source-id: 3a59e814a62f1ee33a6af69a0c88065f23f1ef2b
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 3, 2023
1 parent aa5141c commit 87c2453
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "RawPropsParser.h"

#include <folly/Likely.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/RawProps.h>

Expand All @@ -21,7 +20,7 @@ namespace facebook::react {
const RawValue* RawPropsParser::at(
const RawProps& rawProps,
const RawPropsKey& key) const noexcept {
if (UNLIKELY(!ready_)) {
if (!ready_) [[unlikely]] {
// Check against the same key being inserted more than once.
// This happens commonly with nested Props structs, where the higher-level
// struct may access all fields, and then the nested Props struct may
Expand Down Expand Up @@ -69,8 +68,8 @@ const RawValue* RawPropsParser::at(
do {
rawProps.keyIndexCursor_++;

if (UNLIKELY(
static_cast<size_t>(rawProps.keyIndexCursor_) >= keys_.size())) {
if (static_cast<size_t>(rawProps.keyIndexCursor_) >= keys_.size())
[[unlikely]] {
#ifdef REACT_NATIVE_DEBUG
if (resetLoop) {
LOG(ERROR)
Expand All @@ -82,7 +81,7 @@ const RawValue* RawPropsParser::at(
#endif
rawProps.keyIndexCursor_ = 0;
}
} while (UNLIKELY(key != keys_[rawProps.keyIndexCursor_]));
} while (key != keys_[rawProps.keyIndexCursor_]);

auto valueIndex = rawProps.keyIndexToValueIndex_[rawProps.keyIndexCursor_];
return valueIndex == kRawPropsValueIndexEmpty ? nullptr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <optional>

#include <folly/Likely.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/RawPropsKey.h>
Expand Down Expand Up @@ -117,13 +116,13 @@ T convertRawProp(
const char* namePrefix = nullptr,
const char* nameSuffix = nullptr) {
const auto* rawValue = rawProps.at(name, namePrefix, nameSuffix);
if (LIKELY(rawValue == nullptr)) {
if (rawValue == nullptr) [[likely]] {
return sourceValue;
}

// Special case: `null` always means "the prop was removed, use default
// value".
if (UNLIKELY(!rawValue->hasValue())) {
if (!rawValue->hasValue()) [[unlikely]] {
return defaultValue;
}

Expand Down

0 comments on commit 87c2453

Please sign in to comment.