Make use of modern standard types

Reviewed By: lucasr

Differential Revision: D3649096

fbshipit-source-id: dc9fc8861c3106494c5d00d6ac337da50a4c945b
This commit is contained in:
Emil Sjolander 2016-08-02 08:06:55 -07:00 committed by Facebook Github Bot
parent aba87550cc
commit ef585e33b1
5 changed files with 52 additions and 53 deletions

View File

@ -10,9 +10,6 @@
#ifndef __CSS_LAYOUT_INTERNAL_H #ifndef __CSS_LAYOUT_INTERNAL_H
#define __CSS_LAYOUT_INTERNAL_H #define __CSS_LAYOUT_INTERNAL_H
#include <stdio.h>
#include <stdlib.h>
#include "CSSLayout.h" #include "CSSLayout.h"
#include "CSSNodeList.h" #include "CSSNodeList.h"
@ -43,10 +40,10 @@ typedef struct CSSLayout {
// Instead of recomputing the entire layout every single time, we // Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed // cache some information to break early when nothing changed
int generationCount; uint32_t generationCount;
CSSDirection lastParentDirection; CSSDirection lastParentDirection;
int nextCachedMeasurementsIndex; uint32_t nextCachedMeasurementsIndex;
CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT]; CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT];
float measuredDimensions[2]; float measuredDimensions[2];
@ -86,7 +83,7 @@ typedef struct CSSStyle {
typedef struct CSSNode { typedef struct CSSNode {
CSSStyle style; CSSStyle style;
CSSLayout layout; CSSLayout layout;
int lineIndex; uint32_t lineIndex;
bool hasNewLayout; bool hasNewLayout;
bool isTextNode; bool isTextNode;
CSSNodeRef parent; CSSNodeRef parent;

View File

@ -7,10 +7,6 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "CSSLayout-internal.h" #include "CSSLayout-internal.h"
@ -102,7 +98,7 @@ void _CSSNodeMarkDirty(CSSNodeRef node) {
} }
} }
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, unsigned int index) { void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index) {
CSSNodeListInsert(node->children, child, index); CSSNodeListInsert(node->children, child, index);
child->parent = node; child->parent = node;
_CSSNodeMarkDirty(node); _CSSNodeMarkDirty(node);
@ -114,11 +110,11 @@ void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child) {
_CSSNodeMarkDirty(node); _CSSNodeMarkDirty(node);
} }
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, unsigned int index) { CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index) {
return CSSNodeListGet(node->children, index); return CSSNodeListGet(node->children, index);
} }
unsigned int CSSNodeChildCount(CSSNodeRef node) { uint32_t CSSNodeChildCount(CSSNodeRef node) {
return CSSNodeListCount(node->children); return CSSNodeListCount(node->children);
} }
@ -214,7 +210,7 @@ CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[CSSDimensionWidth]);
CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[CSSDimensionHeight]); CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[CSSDimensionHeight]);
CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction); CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction);
int gCurrentGenerationCount = 0; uint32_t gCurrentGenerationCount = 0;
bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeight, CSSDirection parentDirection, bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeight, CSSDirection parentDirection,
CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout, char* reason); CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout, char* reason);
@ -230,8 +226,8 @@ static bool eq(float a, float b) {
return fabs(a - b) < 0.0001; return fabs(a - b) < 0.0001;
} }
static void indent(int n) { static void indent(uint32_t n) {
for (int i = 0; i < n; ++i) { for (uint32_t i = 0; i < n; ++i) {
printf(" "); printf(" ");
} }
} }
@ -259,7 +255,7 @@ static bool four_equal(float four[4]) {
static void print_css_node_rec( static void print_css_node_rec(
CSSNode* node, CSSNode* node,
CSSPrintOptions options, CSSPrintOptions options,
int level uint32_t level
) { ) {
indent(level); indent(level);
printf("{"); printf("{");
@ -382,10 +378,10 @@ static void print_css_node_rec(
print_number_nan("bottom", node->style.position[CSSPositionBottom]); print_number_nan("bottom", node->style.position[CSSPositionBottom]);
} }
unsigned int childCount = CSSNodeListCount(node->children); uint32_t childCount = CSSNodeListCount(node->children);
if (options & CSSPrintOptionsChildren && childCount > 0) { if (options & CSSPrintOptionsChildren && childCount > 0) {
printf("children: [\n"); printf("children: [\n");
for (unsigned int i = 0; i < childCount; ++i) { for (uint32_t i = 0; i < childCount; ++i) {
print_css_node_rec(CSSNodeGetChild(node, i), options, level + 1); print_css_node_rec(CSSNodeGetChild(node, i), options, level + 1);
} }
indent(level); indent(level);
@ -852,7 +848,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
// For nodes with no children, use the available values if they were provided, or // For nodes with no children, use the available values if they were provided, or
// the minimum size as indicated by the padding and border sizes. // the minimum size as indicated by the padding and border sizes.
unsigned int childCount = CSSNodeListCount(node->children); uint32_t childCount = CSSNodeListCount(node->children);
if (childCount == 0) { if (childCount == 0) {
node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow,
(widthMeasureMode == CSSMeasureModeUndefined || widthMeasureMode == CSSMeasureModeAtMost) ? (widthMeasureMode == CSSMeasureModeUndefined || widthMeasureMode == CSSMeasureModeAtMost) ?
@ -924,7 +920,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
// STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
CSSNode* child; CSSNode* child;
unsigned int i; uint32_t i;
float childWidth; float childWidth;
float childHeight; float childHeight;
CSSMeasureMode childWidthMeasureMode; CSSMeasureMode childWidthMeasureMode;
@ -1031,11 +1027,11 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
// Indexes of children that represent the first and last items in the line. // Indexes of children that represent the first and last items in the line.
int startOfLineIndex = 0; uint32_t startOfLineIndex = 0;
int endOfLineIndex = 0; uint32_t endOfLineIndex = 0;
// Number of lines. // Number of lines.
int lineCount = 0; uint32_t lineCount = 0;
// Accumulated cross dimensions of all lines so far. // Accumulated cross dimensions of all lines so far.
float totalLineCrossDim = 0; float totalLineCrossDim = 0;
@ -1047,7 +1043,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
// Number of items on the currently line. May be different than the difference // Number of items on the currently line. May be different than the difference
// between start and end indicates because we skip over absolute-positioned items. // between start and end indicates because we skip over absolute-positioned items.
int itemsOnLine = 0; uint32_t itemsOnLine = 0;
// sizeConsumedOnCurrentLine is accumulation of the dimensions and margin // sizeConsumedOnCurrentLine is accumulation of the dimensions and margin
// of all the children on the current line. This will be used in order to // 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
} }
} }
int endIndex = 0; uint32_t endIndex = 0;
for (i = 0; i < lineCount; ++i) { for (i = 0; i < lineCount; ++i) {
int startIndex = endIndex; uint32_t startIndex = endIndex;
int j; uint32_t j;
// compute the line's height and find the endIndex // compute the line's height and find the endIndex
float lineHeight = 0; float lineHeight = 0;
@ -1654,7 +1650,7 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
} }
} }
int gDepth = 0; uint32_t gDepth = 0;
bool gPrintTree = false; bool gPrintTree = false;
bool gPrintChanges = false; bool gPrintChanges = false;
bool gPrintSkips = false; bool gPrintSkips = false;
@ -1808,7 +1804,7 @@ bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeig
cachedResults = &layout->cached_layout; cachedResults = &layout->cached_layout;
} else { } else {
// Try to use the measurement cache. // Try to use the measurement cache.
for (int i = 0; i < layout->nextCachedMeasurementsIndex; i++) { for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
if (canUseCachedMeasurement(node->isTextNode, availableWidth, availableHeight, marginAxisRow, marginAxisColumn, if (canUseCachedMeasurement(node->isTextNode, availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
widthMeasureMode, heightMeasureMode, layout->cachedMeasurements[i])) { widthMeasureMode, heightMeasureMode, layout->cachedMeasurements[i])) {
cachedResults = &layout->cachedMeasurements[i]; cachedResults = &layout->cachedMeasurements[i];
@ -1825,7 +1821,7 @@ bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeig
cachedResults = &layout->cached_layout; cachedResults = &layout->cached_layout;
} }
} else { } else {
for (int i = 0; i < layout->nextCachedMeasurementsIndex; i++) { for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
if (eq(layout->cachedMeasurements[i].availableWidth, availableWidth) && if (eq(layout->cachedMeasurements[i].availableWidth, availableWidth) &&
eq(layout->cachedMeasurements[i].availableHeight, availableHeight) && eq(layout->cachedMeasurements[i].availableHeight, availableHeight) &&
layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode && layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode &&

View File

@ -10,7 +10,12 @@
#ifndef __CSS_LAYOUT_H #ifndef __CSS_LAYOUT_H
#define __CSS_LAYOUT_H #define __CSS_LAYOUT_H
#include <assert.h>
#include <math.h> #include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#ifndef __cplusplus #ifndef __cplusplus
#include <stdbool.h> #include <stdbool.h>
#endif #endif
@ -117,10 +122,10 @@ CSSNodeRef CSSNodeNew();
void CSSNodeInit(CSSNodeRef node); void CSSNodeInit(CSSNodeRef node);
void CSSNodeFree(CSSNodeRef node); void CSSNodeFree(CSSNodeRef node);
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, unsigned int index); void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index);
void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child); void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child);
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, unsigned int index); CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index);
unsigned int CSSNodeChildCount(CSSNodeRef node); uint32_t CSSNodeChildCount(CSSNodeRef node);
void CSSNodeCalculateLayout( void CSSNodeCalculateLayout(
CSSNodeRef node, CSSNodeRef node,

View File

@ -7,19 +7,15 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "CSSNodeList.h" #include "CSSNodeList.h"
struct CSSNodeList { struct CSSNodeList {
int capacity; uint32_t capacity;
int count; uint32_t count;
void **items; void **items;
}; };
CSSNodeListRef CSSNodeListNew(unsigned int initialCapacity) { CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList)); CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
assert(list != NULL); assert(list != NULL);
@ -35,7 +31,7 @@ void CSSNodeListFree(CSSNodeListRef list) {
free(list); free(list);
} }
unsigned int CSSNodeListCount(CSSNodeListRef list) { uint32_t CSSNodeListCount(CSSNodeListRef list) {
return list->count; return list->count;
} }
@ -43,14 +39,14 @@ void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
CSSNodeListInsert(list, node, list->count); CSSNodeListInsert(list, node, list->count);
} }
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index) { void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
if (list->count == list->capacity) { if (list->count == list->capacity) {
list->capacity *= 2; list->capacity *= 2;
list->items = realloc(list->items, sizeof(void*) * list->capacity); list->items = realloc(list->items, sizeof(void*) * list->capacity);
assert(list->items != NULL); assert(list->items != NULL);
} }
for (unsigned int i = list->count; i > index; i--) { for (uint32_t i = list->count; i > index; i--) {
list->items[i] = list->items[i - 1]; list->items[i] = list->items[i - 1];
} }
@ -58,11 +54,11 @@ void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index)
list->items[index] = node; list->items[index] = node;
} }
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index) { CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
CSSNodeRef removed = list->items[index]; CSSNodeRef removed = list->items[index];
list->items[index] = NULL; list->items[index] = NULL;
for (unsigned int i = index; i < list->count - 1; i++) { for (uint32_t i = index; i < list->count - 1; i++) {
list->items[i] = list->items[i + 1]; list->items[i] = list->items[i + 1];
list->items[i + 1] = NULL; list->items[i + 1] = NULL;
} }
@ -72,7 +68,7 @@ CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index) {
} }
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) { CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
for (unsigned int i = 0; i < list->count; i++) { for (uint32_t i = 0; i < list->count; i++) {
if (list->items[i] == node) { if (list->items[i] == node) {
return CSSNodeListRemove(list, i); return CSSNodeListRemove(list, i);
} }
@ -81,6 +77,6 @@ CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
return NULL; return NULL;
} }
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, unsigned int index) { CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) {
return list->items[index]; return list->items[index];
} }

View File

@ -10,20 +10,25 @@
#ifndef __CSS_NODE_LIST_H #ifndef __CSS_NODE_LIST_H
#define __CSS_NODE_LIST_H #define __CSS_NODE_LIST_H
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <CSSLayout/CSSLayout.h> #include <CSSLayout/CSSLayout.h>
CSS_EXTERN_C_BEGIN CSS_EXTERN_C_BEGIN
typedef struct CSSNodeList * CSSNodeListRef; typedef struct CSSNodeList * CSSNodeListRef;
CSSNodeListRef CSSNodeListNew(unsigned int initialCapacity); CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity);
void CSSNodeListFree(CSSNodeListRef list); void CSSNodeListFree(CSSNodeListRef list);
unsigned int CSSNodeListCount(CSSNodeListRef list); uint32_t CSSNodeListCount(CSSNodeListRef list);
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node); void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node);
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index); void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index);
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index); CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index);
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node); CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node);
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, unsigned int index); CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index);
CSS_EXTERN_C_END CSS_EXTERN_C_END