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

View File

@ -7,10 +7,6 @@
* 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 "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);
child->parent = node;
_CSSNodeMarkDirty(node);
@ -114,11 +110,11 @@ void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child) {
_CSSNodeMarkDirty(node);
}
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, unsigned int index) {
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index) {
return CSSNodeListGet(node->children, index);
}
unsigned int CSSNodeChildCount(CSSNodeRef node) {
uint32_t CSSNodeChildCount(CSSNodeRef node) {
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(CSSDirection, Direction, direction);
int gCurrentGenerationCount = 0;
uint32_t gCurrentGenerationCount = 0;
bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeight, CSSDirection parentDirection,
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;
}
static void indent(int n) {
for (int i = 0; i < n; ++i) {
static void indent(uint32_t n) {
for (uint32_t i = 0; i < n; ++i) {
printf(" ");
}
}
@ -259,7 +255,7 @@ static bool four_equal(float four[4]) {
static void print_css_node_rec(
CSSNode* node,
CSSPrintOptions options,
int level
uint32_t level
) {
indent(level);
printf("{");
@ -382,10 +378,10 @@ static void print_css_node_rec(
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) {
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);
}
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
// 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) {
node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow,
(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
CSSNode* child;
unsigned int i;
uint32_t i;
float childWidth;
float childHeight;
CSSMeasureMode childWidthMeasureMode;
@ -1031,11 +1027,11 @@ static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableH
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
// Indexes of children that represent the first and last items in the line.
int startOfLineIndex = 0;
int endOfLineIndex = 0;
uint32_t startOfLineIndex = 0;
uint32_t endOfLineIndex = 0;
// Number of lines.
int lineCount = 0;
uint32_t lineCount = 0;
// Accumulated cross dimensions of all lines so far.
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
// 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
// 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) {
int startIndex = endIndex;
int j;
uint32_t startIndex = endIndex;
uint32_t j;
// compute the line's height and find the endIndex
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 gPrintChanges = false;
bool gPrintSkips = false;
@ -1808,7 +1804,7 @@ bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeig
cachedResults = &layout->cached_layout;
} else {
// 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,
widthMeasureMode, heightMeasureMode, layout->cachedMeasurements[i])) {
cachedResults = &layout->cachedMeasurements[i];
@ -1825,7 +1821,7 @@ bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeig
cachedResults = &layout->cached_layout;
}
} 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) &&
eq(layout->cachedMeasurements[i].availableHeight, availableHeight) &&
layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode &&

View File

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

View File

@ -7,19 +7,15 @@
* 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"
struct CSSNodeList {
int capacity;
int count;
uint32_t capacity;
uint32_t count;
void **items;
};
CSSNodeListRef CSSNodeListNew(unsigned int initialCapacity) {
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
assert(list != NULL);
@ -35,7 +31,7 @@ void CSSNodeListFree(CSSNodeListRef list) {
free(list);
}
unsigned int CSSNodeListCount(CSSNodeListRef list) {
uint32_t CSSNodeListCount(CSSNodeListRef list) {
return list->count;
}
@ -43,14 +39,14 @@ void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
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) {
list->capacity *= 2;
list->items = realloc(list->items, sizeof(void*) * list->capacity);
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];
}
@ -58,11 +54,11 @@ void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index)
list->items[index] = node;
}
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index) {
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
CSSNodeRef removed = list->items[index];
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 + 1] = NULL;
}
@ -72,7 +68,7 @@ CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index) {
}
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) {
return CSSNodeListRemove(list, i);
}
@ -81,6 +77,6 @@ CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
return NULL;
}
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, unsigned int index) {
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) {
return list->items[index];
}

View File

@ -10,20 +10,25 @@
#ifndef __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>
CSS_EXTERN_C_BEGIN
typedef struct CSSNodeList * CSSNodeListRef;
CSSNodeListRef CSSNodeListNew(unsigned int initialCapacity);
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity);
void CSSNodeListFree(CSSNodeListRef list);
unsigned int CSSNodeListCount(CSSNodeListRef list);
uint32_t CSSNodeListCount(CSSNodeListRef list);
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node);
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, unsigned int index);
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, unsigned int index);
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index);
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index);
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node);
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, unsigned int index);
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index);
CSS_EXTERN_C_END