C++ Cleanup 7/N: BitUtils (#1351)
Summary: X-link: https://github.com/facebook/react-native/pull/39223 X-link: https://github.com/facebook/react-native/pull/39200 Pull Request resolved: https://github.com/facebook/yoga/pull/1351 ## This diff This splits up `BitUtils.h`, does some minor renaming, and namespace consistency fixes. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. bypass-github-export-checks Reviewed By: shwanton Differential Revision: D48847255 fbshipit-source-id: 4b9722303372f43e936118f8187c0127bceeb1d4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
989f352e03
commit
31b6c0ddc9
@@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/BitUtils.h>
|
||||
#include <yoga/bits/NumericBitfield.h>
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
#include <yoga/Yoga-internal.h>
|
||||
|
||||
@@ -23,7 +23,7 @@ struct LayoutResults {
|
||||
private:
|
||||
static constexpr size_t directionOffset = 0;
|
||||
static constexpr size_t hadOverflowOffset =
|
||||
directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
|
||||
directionOffset + minimumBitCount<YGDirection>();
|
||||
uint8_t flags = 0;
|
||||
|
||||
public:
|
||||
@@ -43,21 +43,16 @@ public:
|
||||
YGCachedMeasurement cachedLayout = YGCachedMeasurement();
|
||||
|
||||
YGDirection direction() const {
|
||||
return facebook::yoga::detail::getEnumData<YGDirection>(
|
||||
flags, directionOffset);
|
||||
return getEnumData<YGDirection>(flags, directionOffset);
|
||||
}
|
||||
|
||||
void setDirection(YGDirection direction) {
|
||||
facebook::yoga::detail::setEnumData<YGDirection>(
|
||||
flags, directionOffset, direction);
|
||||
setEnumData<YGDirection>(flags, directionOffset, direction);
|
||||
}
|
||||
|
||||
bool hadOverflow() const {
|
||||
return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset);
|
||||
}
|
||||
bool hadOverflow() const { return getBooleanData(flags, hadOverflowOffset); }
|
||||
void setHadOverflow(bool hadOverflow) {
|
||||
facebook::yoga::detail::setBooleanData(
|
||||
flags, hadOverflowOffset, hadOverflow);
|
||||
setBooleanData(flags, hadOverflowOffset, hadOverflow);
|
||||
}
|
||||
|
||||
bool operator==(LayoutResults layout) const;
|
||||
|
Reference in New Issue
Block a user