Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use c++20 likely and unlikely #41149

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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