Make use of modern standard types
Summary: stdint.h defines the modern standard c types which have a fixed memory size. This makes the program run more predictably as well as removing the need to ugly double work types such as `unsigned int` or `long long`. Reviewed By: lucasr Differential Revision: D3649096 fbshipit-source-id: dc9fc8861c3106494c5d00d6ac337da50a4c945b
This commit is contained in:
committed by
Facebook Github Bot 7
parent
c72321f8a9
commit
c7d02257e3
@@ -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];
|
||||
}
|
||||
|
Reference in New Issue
Block a user