Fabric: Adding missing noexcept operator to functions in raw props parsing infra

Summary:
This part of the codebase is very perf sensitive and designed to work without exceptions enabled.
Most of the method was `noexcept` all the time, but some of those missing that by mistake.

Reviewed By: sammy-SC

Differential Revision: D17629426

fbshipit-source-id: b311e4b7eff8e2b7cf29518288480d3a812dda44
This commit is contained in:
Valentin Shergin
2019-09-29 20:04:15 -07:00
committed by Facebook Github Bot
parent c7aa6dc827
commit df229590b2
9 changed files with 32 additions and 26 deletions
@@ -46,7 +46,7 @@ RawProps::RawProps(folly::dynamic const &dynamic) noexcept {
dynamic_ = dynamic;
}
void RawProps::parse(RawPropsParser const &parser) const {
void RawProps::parse(RawPropsParser const &parser) const noexcept {
assert(parser_ == nullptr && "A parser was already assigned.");
parser_ = &parser;
parser.preparse(*this);
@@ -74,7 +74,7 @@ class RawProps final {
RawProps(RawProps const &other) noexcept = delete;
RawProps &operator=(RawProps const &other) noexcept = delete;
void parse(RawPropsParser const &parser) const;
void parse(RawPropsParser const &parser) const noexcept;
#ifdef ANDROID
/*
@@ -15,7 +15,8 @@
namespace facebook {
namespace react {
void RawPropsKey::render(char *buffer, RawPropsPropNameLength *length) const {
void RawPropsKey::render(char *buffer, RawPropsPropNameLength *length) const
noexcept {
*length = 0;
// Prefix
@@ -39,7 +40,7 @@ void RawPropsKey::render(char *buffer, RawPropsPropNameLength *length) const {
assert(*length < kPropNameLengthHardCap);
}
RawPropsKey::operator std::string() const {
RawPropsKey::operator std::string() const noexcept {
char buffer[kPropNameLengthHardCap];
RawPropsPropNameLength length = 0;
render(buffer, &length);
@@ -47,13 +48,13 @@ RawPropsKey::operator std::string() const {
return std::string{buffer, length};
}
bool operator==(RawPropsKey const &lhs, RawPropsKey const &rhs) {
bool operator==(RawPropsKey const &lhs, RawPropsKey const &rhs) noexcept {
// Note: We check the name first.
return lhs.name == rhs.name && lhs.prefix == rhs.prefix &&
lhs.suffix == rhs.suffix;
}
bool operator!=(RawPropsKey const &lhs, RawPropsKey const &rhs) {
bool operator!=(RawPropsKey const &lhs, RawPropsKey const &rhs) noexcept {
return !(lhs == rhs);
}
@@ -26,17 +26,17 @@ class RawPropsKey final {
/*
* Converts to `std::string`.
*/
explicit operator std::string() const;
explicit operator std::string() const noexcept;
/*
* Renders compound prop name to given buffer and put the resulting length
* into `length`.
*/
void render(char *buffer, RawPropsPropNameLength *length) const;
void render(char *buffer, RawPropsPropNameLength *length) const noexcept;
};
bool operator==(RawPropsKey const &lhs, RawPropsKey const &rhs);
bool operator!=(RawPropsKey const &lhs, RawPropsKey const &rhs);
bool operator==(RawPropsKey const &lhs, RawPropsKey const &rhs) noexcept;
bool operator!=(RawPropsKey const &lhs, RawPropsKey const &rhs) noexcept;
} // namespace react
} // namespace facebook
@@ -14,7 +14,7 @@
namespace facebook {
namespace react {
int RawPropsKeyMap::comparator(void const *lhs, void const *rhs) {
int RawPropsKeyMap::comparator(void const *lhs, void const *rhs) noexcept {
auto a = static_cast<RawPropsKeyMap::Item const *>(lhs);
auto b = static_cast<RawPropsKeyMap::Item const *>(rhs);
@@ -25,14 +25,16 @@ int RawPropsKeyMap::comparator(void const *lhs, void const *rhs) {
return std::memcmp(a->name, b->name, a->length);
}
void RawPropsKeyMap::insert(RawPropsKey const &key, RawPropsValueIndex value) {
void RawPropsKeyMap::insert(
RawPropsKey const &key,
RawPropsValueIndex value) noexcept {
auto item = Item{};
item.value = value;
key.render(item.name, &item.length);
items_.push_back(item);
}
void RawPropsKeyMap::reindex() {
void RawPropsKeyMap::reindex() noexcept {
// Sorting `items_` by property names length and then lexicographically.
std::qsort(
items_.data(),
@@ -60,7 +62,7 @@ void RawPropsKeyMap::reindex() {
RawPropsValueIndex RawPropsKeyMap::at(
char const *name,
RawPropsPropNameLength length) {
RawPropsPropNameLength length) noexcept {
assert(length > 0);
assert(length < kPropNameLengthHardCap);
// 1. Find the bucket.
@@ -27,22 +27,24 @@ class RawPropsKeyMap final {
/*
* Stores `value` with by given `key`.
*/
void insert(RawPropsKey const &key, RawPropsValueIndex value);
void insert(RawPropsKey const &key, RawPropsValueIndex value) noexcept;
/*
* Reindexes the stored data.
* Must be called before `at` (after calling a bunch of `add`s).
*/
void reindex();
void reindex() noexcept;
/*
* Finds and returns the `value` (some index) by given `key`.
* Returns `kRawPropsValueIndexEmpty` if the value wan't found.
*/
RawPropsValueIndex at(char const *name, RawPropsPropNameLength length);
RawPropsValueIndex at(
char const *name,
RawPropsPropNameLength length) noexcept;
private:
static int comparator(void const *lhs, void const *rhs);
static int comparator(void const *lhs, void const *rhs) noexcept;
struct Item {
RawPropsValueIndex value;
@@ -15,7 +15,7 @@ namespace react {
RawValue const *RawPropsParser::at(
RawProps const &rawProps,
RawPropsKey const &key) const {
RawPropsKey const &key) const noexcept {
if (UNLIKELY(!ready_)) {
// This is not thread-safe part; this happens only during initialization of
// a `ComponentDescriptor` where it is actually safe.
@@ -38,12 +38,12 @@ RawValue const *RawPropsParser::at(
: &rawProps.values_[valueIndex];
}
void RawPropsParser::postPrepare() {
void RawPropsParser::postPrepare() noexcept {
ready_ = true;
nameToIndex_.reindex();
}
void RawPropsParser::preparse(RawProps const &rawProps) const {
void RawPropsParser::preparse(RawProps const &rawProps) const noexcept {
rawProps.keyIndexToValueIndex_.resize(size_, kRawPropsValueIndexEmpty);
// Resetting the cursor, the next increment will give `0`.
@@ -35,7 +35,7 @@ class RawPropsParser final {
* To be used by `ConcreteComponentDescriptor` only.
*/
template <typename PropsT>
void prepare() {
void prepare() noexcept {
static_assert(
std::is_base_of<Props, PropsT>::value,
"PropsT must be a descendant of Props");
@@ -54,17 +54,18 @@ class RawPropsParser final {
/*
* To be used by `RawProps` only.
*/
void preparse(RawProps const &rawProps) const;
void preparse(RawProps const &rawProps) const noexcept;
/*
* Non-generic part of `prepare`.
*/
void postPrepare();
void postPrepare() noexcept;
/*
* To be used by `RawProps` only.
*/
RawValue const *at(RawProps const &rawProps, RawPropsKey const &key) const;
RawValue const *at(RawProps const &rawProps, RawPropsKey const &key) const
noexcept;
mutable better::small_vector<RawPropsKey, kNumberOfPropsPerComponentSoftCap>
keys_{};
@@ -95,7 +95,7 @@ class RawValue {
return castValue(dynamic_, (T *)nullptr);
}
inline explicit operator folly::dynamic() const {
inline explicit operator folly::dynamic() const noexcept {
return dynamic_;
}