Add and run clang format script

Summary: This code used to be auto generated. Let's let clang-format clean up some stuff for us.

Reviewed By: lucasr

Differential Revision: D3662225

fbshipit-source-id: ddd4064cbf9be21ca6a97001ace1b56b4314c86f
This commit is contained in:
Emil Sjolander
2016-08-04 08:20:11 -07:00
committed by Facebook Github Bot 9
parent 9278ff462e
commit efe1595f0e
9 changed files with 680 additions and 541 deletions

View File

@@ -26,9 +26,7 @@ typedef struct CSSCachedMeasurement {
// This value was chosen based on empiracle data. Even the most complicated
// layouts should not require more than 16 entries to fit within the cache.
enum {
CSS_MAX_CACHED_RESULT_COUNT = 16
};
enum { CSS_MAX_CACHED_RESULT_COUNT = 16 };
typedef struct CSSLayout {
float position[4];
@@ -89,9 +87,13 @@ typedef struct CSSNode {
CSSNodeListRef children;
bool isDirty;
struct CSSNode* nextChild;
struct CSSNode *nextChild;
CSSSize (*measure)(void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode);
CSSSize (*measure)(void *context,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
void (*print)(void *context);
void *context;
} CSSNode;

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,7 @@
// Not defined in MSVC++
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
static const unsigned long __nan[2] = { 0xffffffff, 0x7fffffff };
#define NAN (*(const float *)__nan)
#endif
@@ -112,8 +112,9 @@ typedef struct CSSSize {
float height;
} CSSSize;
typedef struct CSSNode * CSSNodeRef;
typedef CSSSize (*CSSMeasureFunc)(void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode);
typedef struct CSSNode *CSSNodeRef;
typedef CSSSize (*CSSMeasureFunc)(
void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode);
typedef void (*CSSPrintFunc)(void *context);
// CSSNode
@@ -127,14 +128,14 @@ CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index);
uint32_t CSSNodeChildCount(CSSNodeRef node);
void CSSNodeCalculateLayout(
CSSNodeRef node,
float availableWidth,
float availableHeight,
CSSDirection parentDirection);
CSSNodeRef node, float availableWidth, float availableHeight, CSSDirection parentDirection);
// Mark a node as dirty. Only valid for nodes with a custom measure function set.
// CSSLayout knows when to mark all other nodes as dirty but because nodes with measure functions
// depends on information not known to CSSLayout they must perform this dirty marking manually.
// Mark a node as dirty. Only valid for nodes with a custom measure function
// set.
// CSSLayout knows when to mark all other nodes as dirty but because nodes with
// measure functions
// depends on information not known to CSSLayout they must perform this dirty
// marking manually.
void CSSNodeMarkDirty(CSSNodeRef node);
bool CSSNodeIsDirty(CSSNodeRef node);
@@ -142,18 +143,17 @@ void CSSNodePrint(CSSNodeRef node, CSSPrintOptions options);
bool isUndefined(float value);
#define CSS_NODE_PROPERTY(type, name, paramName) \
void CSSNodeSet##name(CSSNodeRef node, type paramName); \
type CSSNodeGet##name(CSSNodeRef node);
#define CSS_NODE_PROPERTY(type, name, paramName) \
void CSSNodeSet##name(CSSNodeRef node, type paramName); \
type CSSNodeGet##name(CSSNodeRef node);
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
void CSSNodeStyleSet##name(CSSNodeRef node, type paramName); \
type CSSNodeStyleGet##name(CSSNodeRef node);
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
void CSSNodeStyleSet##name(CSSNodeRef node, type paramName); \
type CSSNodeStyleGet##name(CSSNodeRef node);
#define CSS_NODE_LAYOUT_PROPERTY(type, name) \
type CSSNodeLayoutGet##name(CSSNodeRef node);
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(CSSNodeRef node);
CSS_NODE_PROPERTY(void*, Context, context);
CSS_NODE_PROPERTY(void *, Context, context);
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
CSS_NODE_PROPERTY(bool, IsTextnode, isTextNode);

View File

@@ -10,11 +10,11 @@
#pragma once
#ifdef __cplusplus
# define CSS_EXTERN_C_BEGIN extern "C" {
# define CSS_EXTERN_C_END }
#define CSS_EXTERN_C_BEGIN extern "C" {
#define CSS_EXTERN_C_END }
#else
# define CSS_EXTERN_C_BEGIN
# define CSS_EXTERN_C_END
#define CSS_EXTERN_C_BEGIN
#define CSS_EXTERN_C_END
#endif
#ifndef FB_ASSERTIONS_ENABLED
@@ -27,8 +27,8 @@
#define CSS_ABORT()
#endif
#define CSS_ASSERT(X, message) \
if (!(X)) { \
fprintf(stderr, "%s\n", message); \
CSS_ABORT(); \
}
#define CSS_ASSERT(X, message) \
if (!(X)) { \
fprintf(stderr, "%s\n", message); \
CSS_ABORT(); \
}

View File

@@ -21,19 +21,15 @@ CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
list->capacity = initialCapacity;
list->count = 0;
list->items = malloc(sizeof(void*) * list->capacity);
list->items = malloc(sizeof(void *) * list->capacity);
CSS_ASSERT(list->items != NULL, "Could not allocate memory for items");
return list;
}
void CSSNodeListFree(CSSNodeListRef list) {
free(list);
}
void CSSNodeListFree(CSSNodeListRef list) { free(list); }
uint32_t CSSNodeListCount(CSSNodeListRef list) {
return list->count;
}
uint32_t CSSNodeListCount(CSSNodeListRef list) { return list->count; }
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
CSSNodeListInsert(list, node, list->count);
@@ -42,7 +38,7 @@ void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
if (list->count == list->capacity) {
list->capacity *= 2;
list->items = realloc(list->items, sizeof(void*) * list->capacity);
list->items = realloc(list->items, sizeof(void *) * list->capacity);
CSS_ASSERT(list->items != NULL, "Could not extend allocation for items");
}
@@ -77,6 +73,4 @@ CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
return NULL;
}
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) {
return list->items[index];
}
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) { return list->items[index]; }

View File

@@ -19,7 +19,7 @@
CSS_EXTERN_C_BEGIN
typedef struct CSSNodeList * CSSNodeListRef;
typedef struct CSSNodeList *CSSNodeListRef;
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity);
void CSSNodeListFree(CSSNodeListRef list);

View File

@@ -16,24 +16,24 @@
#define NUM_REPETITIONS 100000
#define CSS_BENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \
clock_t __start; \
clock_t __end; \
{ \
BLOCK \
} \
return 0; \
}
#define CSS_BENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \
clock_t __start; \
clock_t __end; \
{ BLOCK } \
return 0; \
}
#define CSS_BENCHMARK(NAME, BLOCK) \
__start = clock(); \
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { BLOCK } \
__end = clock(); \
__printBenchmarkResult(NAME, __start, __end);
#define CSS_BENCHMARK(NAME, BLOCK) \
__start = clock(); \
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
BLOCK \
} \
__end = clock(); \
__printBenchmarkResult(NAME, __start, __end);
void __printBenchmarkResult(char *name, clock_t start, clock_t end) {
float total = (end - start) / (double) CLOCKS_PER_SEC * 1000;
float total = (end - start) / (double)CLOCKS_PER_SEC * 1000;
float mean = total / NUM_REPETITIONS;
printf("%s: ", name);
printf("%lf ms", mean);

12
format.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
clang-format \
-style="{ \
BasedOnStyle: WebKit, \
IndentWidth: 2, \
ColumnLimit: 100, \
BreakBeforeBraces: Attach, \
BinPackParameters: false, \
PointerAlignment: Right, \
}" "$@" \
-i ./**/*.{h,c,cpp}

View File

@@ -3939,7 +3939,7 @@ TEST(CSSLayoutTest, test_layout_node_with_just_text) {
{
CSSNode *node_0 = root_node;
node_0->measure = measure;
node_0->context = (char *) SMALL_TEXT;
node_0->context = (char *)SMALL_TEXT;
}
CSSNode *root_layout = new_test_css_node();
@@ -3960,7 +3960,7 @@ TEST(CSSLayoutTest, test_layout_node_with_fixed_width_and_custom_measure) {
CSSNode *node_0 = root_node;
node_0->style.dimensions[CSSDimensionWidth] = 100;
node_0->measure = measure;
node_0->context = (char *) MEASURE_WITH_RATIO_2;
node_0->context = (char *)MEASURE_WITH_RATIO_2;
}
CSSNode *root_layout = new_test_css_node();
@@ -3981,7 +3981,7 @@ TEST(CSSLayoutTest, test_layout_node_with_fixed_height_and_custom_measure) {
CSSNode *node_0 = root_node;
node_0->style.dimensions[CSSDimensionHeight] = 100;
node_0->measure = measure;
node_0->context = (char *) MEASURE_WITH_RATIO_2;
node_0->context = (char *)MEASURE_WITH_RATIO_2;
}
CSSNode *root_layout = new_test_css_node();
@@ -4003,7 +4003,7 @@ TEST(CSSLayoutTest, test_should_skip_measure_if_fixed_height_and_width) {
node_0->style.dimensions[CSSDimensionWidth] = 100;
node_0->style.dimensions[CSSDimensionHeight] = 100;
node_0->measure = measure;
node_0->context = (char *) MEASURE_WITH_RATIO_2;
node_0->context = (char *)MEASURE_WITH_RATIO_2;
}
CSSNode *root_layout = new_test_css_node();
@@ -4023,7 +4023,7 @@ TEST(CSSLayoutTest, test_should_layout_node_with_measure) {
{
CSSNode *node_0 = root_node;
node_0->measure = measure;
node_0->context = (char *) MEASURE_WITH_RATIO_2;
node_0->context = (char *)MEASURE_WITH_RATIO_2;
}
CSSNode *root_layout = new_test_css_node();
@@ -4049,7 +4049,7 @@ TEST(CSSLayoutTest, test_should_layout_nested_stacks_with_measure) {
CSSNode *node_1;
node_1 = CSSNodeGetChild(node_0, 0);
node_1->measure = measure;
node_1->context = (char *) MEASURE_WITH_RATIO_2;
node_1->context = (char *)MEASURE_WITH_RATIO_2;
node_1 = CSSNodeGetChild(node_0, 1);
node_1->style.flexDirection = CSSFlexDirectionRow;
node_1->style.overflow = CSSOverflowHidden;
@@ -4059,10 +4059,10 @@ TEST(CSSLayoutTest, test_should_layout_nested_stacks_with_measure) {
CSSNode *node_2;
node_2 = CSSNodeGetChild(node_1, 0);
node_2->measure = measure;
node_2->context = (char *) MEASURE_WITH_RATIO_2;
node_2->context = (char *)MEASURE_WITH_RATIO_2;
node_2 = CSSNodeGetChild(node_1, 1);
node_2->measure = measure;
node_2->context = (char *) MEASURE_WITH_RATIO_2;
node_2->context = (char *)MEASURE_WITH_RATIO_2;
}
}
}
@@ -4113,7 +4113,7 @@ TEST(CSSLayoutTest, test_should_layout_text_node_with_width) {
CSSNode *node_0 = root_node;
node_0->style.dimensions[CSSDimensionWidth] = 10;
node_0->measure = measure;
node_0->context = (char *) SMALL_TEXT;
node_0->context = (char *)SMALL_TEXT;
}
CSSNode *root_layout = new_test_css_node();
@@ -4133,7 +4133,7 @@ TEST(CSSLayoutTest, test_should_layout_text_node_with_padding_and_margin) {
{
CSSNode *node_0 = root_node;
node_0->measure = measure;
node_0->context = (char *) LONG_TEXT;
node_0->context = (char *)LONG_TEXT;
}
CSSNode *root_layout = new_test_css_node();
@@ -4213,7 +4213,7 @@ TEST(CSSLayoutTest, test_should_layout_node_with_text_and_flex) {
node_2 = CSSNodeGetChild(node_1, 0);
node_2->style.flex = 1;
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
}
}
@@ -4265,7 +4265,7 @@ TEST(CSSLayoutTest, test_should_layout_node_text_and_flex_rtl) {
node_2 = CSSNodeGetChild(node_1, 0);
node_2->style.flex = 1;
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
}
}
@@ -4316,7 +4316,7 @@ TEST(CSSLayoutTest, test_should_layout_node_text_and_stretch) {
CSSNode *node_2;
node_2 = CSSNodeGetChild(node_1, 0);
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
}
}
@@ -4368,7 +4368,7 @@ TEST(CSSLayoutTest, test_should_layout_node_text_and_stretch_and_width) {
node_2 = CSSNodeGetChild(node_1, 0);
node_2->style.dimensions[CSSDimensionWidth] = 130;
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
}
}
@@ -4415,7 +4415,7 @@ TEST(CSSLayoutTest, test_should_layout_node_text_bounded_by_parent) {
node_1 = CSSNodeGetChild(node_0, 0);
node_1->style.alignSelf = CSSAlignFlexStart;
node_1->measure = measure;
node_1->context = (char *) LONG_TEXT;
node_1->context = (char *)LONG_TEXT;
}
}
@@ -4468,7 +4468,7 @@ TEST(CSSLayoutTest, test_should_layout_node_text_bounded_by_grand_parent) {
CSSNode *node_2;
node_2 = CSSNodeGetChild(node_1, 0);
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
}
}
@@ -4680,7 +4680,7 @@ TEST(CSSLayoutTest, test_should_layout_text_direction_row) {
node_2->style.margin[CSSPositionStart] = 20;
node_2->style.margin[CSSPositionEnd] = 20;
node_2->measure = measure;
node_2->context = (char *) SMALL_TEXT;
node_2->context = (char *)SMALL_TEXT;
}
}
}
@@ -4737,7 +4737,7 @@ TEST(CSSLayoutTest, test_should_layout_text_direction_row_rtl) {
node_2->style.margin[CSSPositionStart] = 20;
node_2->style.margin[CSSPositionEnd] = 20;
node_2->measure = measure;
node_2->context = (char *) SMALL_TEXT;
node_2->context = (char *)SMALL_TEXT;
}
}
}
@@ -4792,7 +4792,7 @@ TEST(CSSLayoutTest, test_should_layout_text_with_margin) {
node_2->style.margin[CSSPositionStart] = 20;
node_2->style.margin[CSSPositionEnd] = 20;
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
}
}
@@ -5315,7 +5315,8 @@ TEST(CSSLayoutTest, test_should_layout_absolute_node_top_with_right_width_and_no
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_layout_absolute_node_left_with_right_width_and_no_parent_dimension) {
TEST(
CSSLayoutTest, test_should_layout_absolute_node_left_with_right_width_and_no_parent_dimension) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -5350,7 +5351,8 @@ TEST(CSSLayoutTest, test_should_layout_absolute_node_left_with_right_width_and_n
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_layout_node_with_border_bottom__insidejustifyContent_space_between_container) {
TEST(CSSLayoutTest,
test_should_layout_node_with_border_bottom__insidejustifyContent_space_between_container) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -5384,7 +5386,8 @@ TEST(CSSLayoutTest, test_should_layout_node_with_border_bottom__insidejustifyCon
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_layout_node_with_negative_margin_top_inside_justifyContent_center_container) {
TEST(CSSLayoutTest,
test_should_layout_node_with_negative_margin_top_inside_justifyContent_center_container) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -5418,7 +5421,8 @@ TEST(CSSLayoutTest, test_should_layout_node_with_negative_margin_top_inside_just
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_layout_node_with_margin_top_inside_justifyContent_center_container) {
TEST(
CSSLayoutTest, test_should_layout_node_with_margin_top_inside_justifyContent_center_container) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -7742,7 +7746,7 @@ TEST(CSSLayoutTest, test_should_propagate_size_contraints_from_flex_parent) {
node_2->style.flex = 1;
node_2->style.dimensions[CSSDimensionHeight] = 10;
node_2->measure = measure;
node_2->context = (char *) MEASURE_WITH_MATCH_PARENT;
node_2->context = (char *)MEASURE_WITH_MATCH_PARENT;
}
}
}
@@ -8166,7 +8170,8 @@ TEST(CSSLayoutTest, test_should_shrink_column_node_when_there_is_no_space_left_o
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_not_shrink_column_node_with_siblings_when_there_is_space_left_over) {
TEST(
CSSLayoutTest, test_should_not_shrink_column_node_with_siblings_when_there_is_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8302,7 +8307,8 @@ TEST(CSSLayoutTest, test_should_shrink_column_node_with_siblings_when_there_is_n
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_shrink_column_nodes_proporional_to_their_main_size_when_there_is_no_space_left_over) {
TEST(CSSLayoutTest,
test_should_shrink_column_nodes_proporional_to_their_main_size_when_there_is_no_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8462,7 +8468,8 @@ TEST(CSSLayoutTest, test_should_shrink_visible_row_node_when_there_is_no_space_l
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_not_shrink_visible_row_node_with_siblings_when_there_is_space_left_over) {
TEST(CSSLayoutTest,
test_should_not_shrink_visible_row_node_with_siblings_when_there_is_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8531,7 +8538,8 @@ TEST(CSSLayoutTest, test_should_not_shrink_visible_row_node_with_siblings_when_t
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_shrink_visible_row_node_with_siblings_when_there_is_no_space_left_over) {
TEST(CSSLayoutTest,
test_should_shrink_visible_row_node_with_siblings_when_there_is_no_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8763,7 +8771,8 @@ TEST(CSSLayoutTest, test_should_shrink_hidden_row_node_when_there_is_no_space_le
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_not_shrink_hidden_row_node_with_siblings_when_there_is_space_left_over) {
TEST(CSSLayoutTest,
test_should_not_shrink_hidden_row_node_with_siblings_when_there_is_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8833,7 +8842,8 @@ TEST(CSSLayoutTest, test_should_not_shrink_hidden_row_node_with_siblings_when_th
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_shrink_hidden_row_node_with_siblings_when_there_is_no_space_left_over) {
TEST(CSSLayoutTest,
test_should_shrink_hidden_row_node_with_siblings_when_there_is_no_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8903,7 +8913,8 @@ TEST(CSSLayoutTest, test_should_shrink_hidden_row_node_with_siblings_when_there_
ASSERT_TRUE(test(root_node, root_layout));
}
TEST(CSSLayoutTest, test_should_shrink_hidden_row_nodes_propertional_to_main_size_when_there_is_no_space_left_over) {
TEST(CSSLayoutTest,
test_should_shrink_hidden_row_nodes_propertional_to_main_size_when_there_is_no_space_left_over) {
CSSNode *root_node = new_test_css_node();
{
CSSNode *node_0 = root_node;
@@ -8983,7 +8994,7 @@ TEST(CSSLayoutTest, test_should_not_shrink_text_node_with_siblings_when_there_is
CSSNode *node_2;
node_2 = CSSNodeGetChild(node_1, 0);
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
node_1 = CSSNodeGetChild(node_0, 2);
node_1->style.dimensions[CSSDimensionWidth] = 15;
@@ -9055,7 +9066,7 @@ TEST(CSSLayoutTest, test_should_shrink_text_node_with_siblings_when_there_is_no_
node_2 = CSSNodeGetChild(node_1, 0);
node_2->style.flex = -1;
node_2->measure = measure;
node_2->context = (char *) LONG_TEXT;
node_2->context = (char *)LONG_TEXT;
}
node_1 = CSSNodeGetChild(node_0, 2);
node_1->style.dimensions[CSSDimensionWidth] = 15;