Skip to content

Commit

Permalink
Use fbsource clang-format config
Browse files Browse the repository at this point in the history
Summary:
This mirrors the clang-format config used by fbsource to Yoga.

They are pretty similar, except for an annoying habit where Yoga's previous forced small functions in headers to be a a single line, so you would get a combination of multiline and single line functions next to each other which are hard to read. That is what motivated this change.

It also enforces header ordering (yay). I don't think we have any side-effect causing headers, so this should be safe.

Reviewed By: yungsters

Differential Revision: D49248994

fbshipit-source-id: 66998395e7c0158ff9d9fb1bee44e8401bdd8f21
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 14, 2023
1 parent 9d21e3e commit f9c2c27
Show file tree
Hide file tree
Showing 51 changed files with 521 additions and 469 deletions.
59 changes: 0 additions & 59 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,61 +1,3 @@
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyReturnTypeOnItsOwnLine: 2000
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
Standard: Cpp11
UseTab: Never
---
Language: ObjC
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
Expand Down Expand Up @@ -165,4 +107,3 @@ Standard: Latest
TabWidth: 8
UseCRLF: false
UseTab: Never
...
18 changes: 8 additions & 10 deletions benchmark/YGBenchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#define YGBENCHMARKS(BLOCK) \
int main(int argc, char const* argv[]) { \
(void) argc; \
(void) argv; \
(void)argc; \
(void)argv; \
clock_t __start; \
clock_t __endTimes[NUM_REPETITIONS]; \
{ BLOCK } \
Expand All @@ -33,8 +33,8 @@
__printBenchmarkResult(NAME, __start, __endTimes);

static int __compareDoubles(const void* a, const void* b) {
double arg1 = *(const double*) a;
double arg2 = *(const double*) b;
double arg1 = *(const double*)a;
double arg2 = *(const double*)b;

if (arg1 < arg2) {
return -1;
Expand All @@ -47,16 +47,14 @@ static int __compareDoubles(const void* a, const void* b) {
return 0;
}

static void __printBenchmarkResult(
char* name,
clock_t start,
clock_t* endTimes) {
static void
__printBenchmarkResult(char* name, clock_t start, clock_t* endTimes) {
double timesInMs[NUM_REPETITIONS];
double mean = 0;
clock_t lastEnd = start;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
timesInMs[i] =
((double) (endTimes[i] - lastEnd)) / (double) CLOCKS_PER_SEC * 1000;
((double)(endTimes[i] - lastEnd)) / (double)CLOCKS_PER_SEC * 1000;
lastEnd = endTimes[i];
mean += timesInMs[i];
}
Expand All @@ -81,7 +79,7 @@ static YGSize _measure(
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
(void) node;
(void)node;
return (YGSize){
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
.height = heightMode == YGMeasureModeUndefined ? 10 : height,
Expand Down
2 changes: 1 addition & 1 deletion java/jni/LayoutContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace facebook::yoga::vanillajni {

// TODO: This should not be exported or used outside of the JNI bindings
class YG_EXPORT LayoutContext {
public:
public:
// Sets a context on the current thread for the duration of the Provider's
// lifetime. This context should be set during the layout process to allow
// layout callbacks to access context-data specific to the layout pass.
Expand Down
16 changes: 11 additions & 5 deletions java/jni/ScopedGlobalRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ScopedGlobalRef {
std::is_same<T, jbooleanArray>(),
"ScopedGlobalRef instantiated for invalid type");

public:
public:
/**
* Constructs a ScopedGlobalRef with a JNI global reference.
*
Expand All @@ -82,7 +82,9 @@ class ScopedGlobalRef {
return *this;
}

~ScopedGlobalRef() { reset(); }
~ScopedGlobalRef() {
reset();
}

/**
* Deletes the currently held reference and reassigns a new one to the
Expand Down Expand Up @@ -111,17 +113,21 @@ class ScopedGlobalRef {
/**
* Returns the underlying JNI global reference.
*/
T get() const { return mGlobalRef; }
T get() const {
return mGlobalRef;
}

/**
* Returns true if the underlying JNI reference is not NULL.
*/
operator bool() const { return mGlobalRef != NULL; }
operator bool() const {
return mGlobalRef != NULL;
}

ScopedGlobalRef(const ScopedGlobalRef& ref) = delete;
ScopedGlobalRef& operator=(const ScopedGlobalRef& other) = delete;

private:
private:
T mGlobalRef;
};

Expand Down
16 changes: 11 additions & 5 deletions java/jni/ScopedLocalRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ScopedLocalRef {
std::is_same<T, jbooleanArray>(),
"ScopedLocalRef instantiated for invalid type");

public:
public:
/**
* Constructs a ScopedLocalRef with a JNI local reference.
*
Expand All @@ -81,7 +81,9 @@ class ScopedLocalRef {
return *this;
}

~ScopedLocalRef() { reset(); }
~ScopedLocalRef() {
reset();
}

/**
* Deletes the currently held reference and reassigns a new one to the
Expand Down Expand Up @@ -110,17 +112,21 @@ class ScopedLocalRef {
/**
* Returns the underlying JNI local reference.
*/
T get() const { return mLocalRef; }
T get() const {
return mLocalRef;
}

/**
* Returns true if the underlying JNI reference is not NULL.
*/
operator bool() const { return mLocalRef != NULL; }
operator bool() const {
return mLocalRef != NULL;
}

ScopedLocalRef(const ScopedLocalRef& ref) = delete;
ScopedLocalRef& operator=(const ScopedLocalRef& other) = delete;

private:
private:
JNIEnv* mEnv;
T mLocalRef;
};
Expand Down
14 changes: 9 additions & 5 deletions java/jni/YGJNI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ union YGNodeContext {
class YGNodeEdges {
int32_t edges_;

public:
public:
enum Edge {
MARGIN = 1,
PADDING = 2,
Expand All @@ -48,14 +48,18 @@ class YGNodeEdges {
YGNodeSetContext(node, context.asVoidPtr);
}

bool has(Edge edge) { return (edges_ & edge) == edge; }
bool has(Edge edge) {
return (edges_ & edge) == edge;
}

YGNodeEdges& add(Edge edge) {
edges_ |= edge;
return *this;
}

int get() { return edges_; }
int get() {
return edges_;
}
};

struct YogaValue {
Expand All @@ -64,10 +68,10 @@ struct YogaValue {
static jlong asJavaLong(const YGValue& value) {
uint32_t valueBytes = 0;
memcpy(&valueBytes, &value.value, sizeof valueBytes);
return ((jlong) value.unit) << 32 | valueBytes;
return ((jlong)value.unit) << 32 | valueBytes;
}
constexpr static jlong undefinedAsJavaLong() {
return ((jlong) YGUnitUndefined) << 32 | NAN_BYTES;
return ((jlong)YGUnitUndefined) << 32 | NAN_BYTES;
}
};
} // namespace
Loading

0 comments on commit f9c2c27

Please sign in to comment.