Summary: X-link: https://github.com/facebook/litho/pull/976 Pull Request resolved: https://github.com/facebook/yoga/pull/1586 X-link: https://github.com/facebook/react-native/pull/43299 Add the React Clang Tidy config to Yoga, run the auto fixes, and make some manual mechanical tweaks. Notably, the automatic changes to the infra for generating a Yoga tree from JSON capture make it 70% faster. Before: {F1463947076} After: {F1463946802} This also cleans up all the no-op shallow const parameters in headers. {F1463943386} Not all checks are available in all environments, but that is okay, as Clang Tidy will gracefully skip them. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D54461054 fbshipit-source-id: dbd2d9ce51afd3174d1f2c6d439fa7d08baff46f
78 lines
1.7 KiB
C++
78 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <yoga/Yoga.h>
|
|
|
|
const short int LAYOUT_EDGE_SET_FLAG_INDEX = 0;
|
|
const short int LAYOUT_WIDTH_INDEX = 1;
|
|
const short int LAYOUT_HEIGHT_INDEX = 2;
|
|
const short int LAYOUT_LEFT_INDEX = 3;
|
|
const short int LAYOUT_TOP_INDEX = 4;
|
|
const short int LAYOUT_DIRECTION_INDEX = 5;
|
|
const short int LAYOUT_MARGIN_START_INDEX = 6;
|
|
const short int LAYOUT_PADDING_START_INDEX = 10;
|
|
const short int LAYOUT_BORDER_START_INDEX = 14;
|
|
|
|
namespace {
|
|
|
|
const int HAS_NEW_LAYOUT = 16;
|
|
|
|
union YGNodeContext {
|
|
int32_t edgesSet = 0;
|
|
void* asVoidPtr;
|
|
};
|
|
|
|
class YGNodeEdges {
|
|
int32_t edges_;
|
|
|
|
public:
|
|
enum Edge {
|
|
MARGIN = 1,
|
|
PADDING = 2,
|
|
BORDER = 4,
|
|
};
|
|
|
|
explicit YGNodeEdges(YGNodeRef node) {
|
|
auto context = YGNodeContext{};
|
|
context.asVoidPtr = YGNodeGetContext(node);
|
|
edges_ = context.edgesSet;
|
|
}
|
|
|
|
void setOn(YGNodeRef node) {
|
|
auto context = YGNodeContext{};
|
|
context.edgesSet = edges_;
|
|
YGNodeSetContext(node, context.asVoidPtr);
|
|
}
|
|
|
|
bool has(Edge edge) {
|
|
return (edges_ & edge) == edge;
|
|
}
|
|
|
|
YGNodeEdges& add(Edge edge) {
|
|
edges_ |= edge;
|
|
return *this;
|
|
}
|
|
|
|
int get() {
|
|
return edges_;
|
|
}
|
|
};
|
|
|
|
struct YogaValue {
|
|
static constexpr jint NAN_BYTES = 0x7fc00000;
|
|
|
|
static jlong asJavaLong(const YGValue& value) {
|
|
uint32_t valueBytes = 0;
|
|
memcpy(&valueBytes, &value.value, sizeof valueBytes);
|
|
return ((jlong)value.unit) << 32 | valueBytes;
|
|
}
|
|
constexpr static jlong undefinedAsJavaLong() {
|
|
return ((jlong)YGUnitUndefined) << 32 | NAN_BYTES;
|
|
}
|
|
};
|
|
} // namespace
|