Skip to content

Commit ef585e3

Browse files
Emil SjolanderFacebook Github Bot
authored andcommitted
Make use of modern standard types
Reviewed By: lucasr Differential Revision: D3649096 fbshipit-source-id: dc9fc8861c3106494c5d00d6ac337da50a4c945b
1 parent aba8755 commit ef585e3

File tree

5 files changed

+52
-53
lines changed

5 files changed

+52
-53
lines changed

React/CSSLayout/CSSLayout-internal.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#ifndef __CSS_LAYOUT_INTERNAL_H
1111
#define __CSS_LAYOUT_INTERNAL_H
1212

13-
#include <stdio.h>
14-
#include <stdlib.h>
15-
1613
#include "CSSLayout.h"
1714
#include "CSSNodeList.h"
1815

@@ -43,10 +40,10 @@ typedef struct CSSLayout {
4340

4441
// Instead of recomputing the entire layout every single time, we
4542
// cache some information to break early when nothing changed
46-
int generationCount;
43+
uint32_t generationCount;
4744
CSSDirection lastParentDirection;
4845

49-
int nextCachedMeasurementsIndex;
46+
uint32_t nextCachedMeasurementsIndex;
5047
CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT];
5148
float measuredDimensions[2];
5249

@@ -86,7 +83,7 @@ typedef struct CSSStyle {
8683
typedef struct CSSNode {
8784
CSSStyle style;
8885
CSSLayout layout;
89-
int lineIndex;
86+
uint32_t lineIndex;
9087
bool hasNewLayout;
9188
bool isTextNode;
9289
CSSNodeRef parent;

React/CSSLayout/CSSLayout.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
#include <assert.h>
11-
#include <math.h>
12-
#include <stdio.h>
13-
#include <stdlib.h>
1410
#include <string.h>
1511

1612
#include "CSSLayout-internal.h"
@@ -102,7 +98,7 @@ void _CSSNodeMarkDirty(CSSNodeRef node) {
10298
}
10399
}
104100

105-
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, unsigned int index) {
101+
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index) {
106102
CSSNodeListInsert(node->children, child, index);
107103
child->parent = node;
108104
_CSSNodeMarkDirty(node);
@@ -114,11 +110,11 @@ void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child) {
114110
_CSSNodeMarkDirty(node);
115111
}
116112

117-
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, unsigned int index) {
113+
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index) {
118114
return CSSNodeListGet(node->children, index);
119115
}
120116

121-
unsigned int CSSNodeChildCount(CSSNodeRef node) {
117+
uint32_t CSSNodeChildCount(CSSNodeRef node) {
122118
return CSSNodeListCount(node->children);
123119
}
124120

@@ -214,7 +210,7 @@ CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[CSSDimensionWidth]);
214210
CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[CSSDimensionHeight]);
215211
CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction);
216212

217-
int gCurrentGenerationCount = 0;
213+
uint32_t gCurrentGenerationCount = 0;
218214

219215
bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeight, CSSDirection parentDirection,
220216
CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout, char* reason);
@@ -230,8 +226,8 @@ static bool eq(float a, float b) {
230226
return fabs(a - b) < 0.0001;
231227
}
232228

233-
static void indent(int n) {
234-
for (int i = 0; i < n; ++i) {
229+
static void indent(uint32_t n) {
230+
for (uint32_t i = 0; i < n; ++i) {
235231
printf(" ");
236232
}
237233
}
@@ -259,7 +255,7 @@ static bool four_equal(float four[4]) {
259255
static void print_css_node_rec(
260256
CSSNode* node,
261257
CSSPrintOptions options,
262-
int level
258+
uint32_t level
263259
) {
264260
indent(level);
265261
printf("{");
@@ -382,10 +378,10 @@ static void print_css_node_rec(
382378
print_number_nan("bottom", node->style.position[CSSPositionBottom]);
383379
}
384380

385-
unsigned int childCount = CSSNodeListCount(node->children);
381+
uint32_t childCount = CSSNodeListCount(node->children);
386382
if (options & CSSPrintOptionsChildren && childCount > 0) {
387383
printf("children: [\n");
388-
for (unsigned int i = 0; i < childCount; ++i) {
384+
for (uint32_t i = 0; i < childCount; ++i) {
389385
print_css_node_rec(CSSNodeGetChild(node, i), options, level + 1);
390386
}
391387
indent(level);
@@ -852,7 +848,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
852848

853849
// For nodes with no children, use the available values if they were provided, or
854850
// the minimum size as indicated by the padding and border sizes.
855-
unsigned int childCount = CSSNodeListCount(node->children);
851+
uint32_t childCount = CSSNodeListCount(node->children);
856852
if (childCount == 0) {
857853
node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow,
858854
(widthMeasureMode == CSSMeasureModeUndefined || widthMeasureMode == CSSMeasureModeAtMost) ?
@@ -924,7 +920,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
924920

925921
// STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
926922
CSSNode* child;
927-
unsigned int i;
923+
uint32_t i;
928924
float childWidth;
929925
float childHeight;
930926
CSSMeasureMode childWidthMeasureMode;
@@ -1031,11 +1027,11 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
10311027
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
10321028

10331029
// Indexes of children that represent the first and last items in the line.
1034-
int startOfLineIndex = 0;
1035-
int endOfLineIndex = 0;
1030+
uint32_t startOfLineIndex = 0;
1031+
uint32_t endOfLineIndex = 0;
10361032

10371033
// Number of lines.
1038-
int lineCount = 0;
1034+
uint32_t lineCount = 0;
10391035

10401036
// Accumulated cross dimensions of all lines so far.
10411037
float totalLineCrossDim = 0;
@@ -1047,7 +1043,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
10471043

10481044
// Number of items on the currently line. May be different than the difference
10491045
// between start and end indicates because we skip over absolute-positioned items.
1050-
int itemsOnLine = 0;
1046+
uint32_t itemsOnLine = 0;
10511047

10521048
// sizeConsumedOnCurrentLine is accumulation of the dimensions and margin
10531049
// of all the children on the current line. This will be used in order to
@@ -1460,10 +1456,10 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
14601456
}
14611457
}
14621458

1463-
int endIndex = 0;
1459+
uint32_t endIndex = 0;
14641460
for (i = 0; i < lineCount; ++i) {
1465-
int startIndex = endIndex;
1466-
int j;
1461+
uint32_t startIndex = endIndex;
1462+
uint32_t j;
14671463

14681464
// compute the line's height and find the endIndex
14691465
float lineHeight = 0;
@@ -1654,7 +1650,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
16541650
}
16551651
}
16561652

1657-
int gDepth = 0;
1653+
uint32_t gDepth = 0;
16581654
bool gPrintTree = false;
16591655
bool gPrintChanges = false;
16601656
bool gPrintSkips = false;
@@ -1808,7 +1804,7 @@ bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeig
18081804
cachedResults = &layout->cached_layout;
18091805
} else {
18101806
// Try to use the measurement cache.
1811-
for (int i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
1807+
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
18121808
if (canUseCachedMeasurement(node->isTextNode, availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
18131809
widthMeasureMode, heightMeasureMode, layout->cachedMeasurements[i])) {
18141810
cachedResults = &layout->cachedMeasurements[i];
@@ -1825,7 +1821,7 @@ bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeig
18251821
cachedResults = &layout->cached_layout;
18261822
}
18271823
} else {
1828-
for (int i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
1824+
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
18291825
if (eq(layout->cachedMeasurements[i].availableWidth, availableWidth) &&
18301826
eq(layout->cachedMeasurements[i].availableHeight, availableHeight) &&
18311827
layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode &&

React/CSSLayout/CSSLayout.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
#ifndef __CSS_LAYOUT_H
1111
#define __CSS_LAYOUT_H
1212

13+
#include <assert.h>
1314
#include <math.h>
15+
#include <stdlib.h>
16+
#include <stdio.h>
17+
#include <stdint.h>
18+
1419
#ifndef __cplusplus
1520
#include <stdbool.h>
1621
#endif
@@ -117,10 +122,10 @@ CSSNodeRef CSSNodeNew();
117122
void CSSNodeInit(CSSNodeRef node);
118123
void CSSNodeFree(CSSNodeRef node);
119124

120-
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, unsigned int index);
125+
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index);
121126
void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child);
122-
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, unsigned int index);
123-
unsigned int CSSNodeChildCount(CSSNodeRef node);
127+
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index);
128+
uint32_t CSSNodeChildCount(CSSNodeRef node);
124129

125130
void CSSNodeCalculateLayout(
126131
CSSNodeRef node,

React/CSSLayout/CSSNodeList.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
#include <assert.h>
11-
#include <stdio.h>
12-
#include <stdlib.h>
13-
1410
#include "CSSNodeList.h"
1511

1612
struct CSSNodeList {
17-
int capacity;
18-
int count;
13+
uint32_t capacity;
14+
uint32_t count;
1915
void **items;
2016
};
2117

22-
CSSNodeListRef CSSNodeListNew(unsigned int initialCapacity) {
18+
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
2319
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
2420
assert(list != NULL);
2521

@@ -35,34 +31,34 @@ void CSSNodeListFree(CSSNodeListRef list) {
3531
free(list);
3632
}
3733

38-
unsigned int CSSNodeListCount(CSSNodeListRef list) {
34+
uint32_t CSSNodeListCount(CSSNodeListRef list) {
3935
return list->count;
4036
}
4137

4238
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
4339
CSSNodeListInsert(list, node, list->count);
4440
}
4541

46-
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index) {
42+
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
4743
if (list->count == list->capacity) {
4844
list->capacity *= 2;
4945
list->items = realloc(list->items, sizeof(void*) * list->capacity);
5046
assert(list->items != NULL);
5147
}
5248

53-
for (unsigned int i = list->count; i > index; i--) {
49+
for (uint32_t i = list->count; i > index; i--) {
5450
list->items[i] = list->items[i - 1];
5551
}
5652

5753
list->count++;
5854
list->items[index] = node;
5955
}
6056

61-
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index) {
57+
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
6258
CSSNodeRef removed = list->items[index];
6359
list->items[index] = NULL;
6460

65-
for (unsigned int i = index; i < list->count - 1; i++) {
61+
for (uint32_t i = index; i < list->count - 1; i++) {
6662
list->items[i] = list->items[i + 1];
6763
list->items[i + 1] = NULL;
6864
}
@@ -72,7 +68,7 @@ CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index) {
7268
}
7369

7470
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
75-
for (unsigned int i = 0; i < list->count; i++) {
71+
for (uint32_t i = 0; i < list->count; i++) {
7672
if (list->items[i] == node) {
7773
return CSSNodeListRemove(list, i);
7874
}
@@ -81,6 +77,6 @@ CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
8177
return NULL;
8278
}
8379

84-
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, unsigned int index) {
80+
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) {
8581
return list->items[index];
8682
}

React/CSSLayout/CSSNodeList.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,25 @@
1010
#ifndef __CSS_NODE_LIST_H
1111
#define __CSS_NODE_LIST_H
1212

13+
#include <assert.h>
14+
#include <stdlib.h>
15+
#include <stdio.h>
16+
#include <stdint.h>
17+
1318
#include <CSSLayout/CSSLayout.h>
1419

1520
CSS_EXTERN_C_BEGIN
1621

1722
typedef struct CSSNodeList * CSSNodeListRef;
1823

19-
CSSNodeListRef CSSNodeListNew(unsigned int initialCapacity);
24+
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity);
2025
void CSSNodeListFree(CSSNodeListRef list);
21-
unsigned int CSSNodeListCount(CSSNodeListRef list);
26+
uint32_t CSSNodeListCount(CSSNodeListRef list);
2227
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node);
23-
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index);
24-
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index);
28+
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index);
29+
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index);
2530
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node);
26-
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, unsigned int index);
31+
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index);
2732

2833
CSS_EXTERN_C_END
2934

0 commit comments

Comments
 (0)