Use const where possible
Summary: Use const where possible. This does not use const for all variables as that would require too much refactoring for one diff. It does however use const where currently possible as well as does some small refactoring to enable const usage in more locations. Striving for 100% const usage leads to code with is easier to reason about as a reference will always reference the same value. The compiler will also assist if you accidentally override a reference. Reviewed By: IanChilds Differential Revision: D3741999 fbshipit-source-id: 1ba7da5784c3047f2d4c03746890192f724aa65e
This commit is contained in:
committed by
Facebook Github Bot 6
parent
4bcefd8845
commit
ca72b2b796
@@ -15,8 +15,8 @@ struct CSSNodeList {
|
||||
void **items;
|
||||
};
|
||||
|
||||
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
|
||||
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
|
||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) {
|
||||
const CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
|
||||
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
|
||||
|
||||
list->capacity = initialCapacity;
|
||||
@@ -27,20 +27,20 @@ CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
|
||||
return list;
|
||||
}
|
||||
|
||||
void CSSNodeListFree(CSSNodeListRef list) {
|
||||
void CSSNodeListFree(const CSSNodeListRef list) {
|
||||
free(list->items);
|
||||
free(list);
|
||||
}
|
||||
|
||||
uint32_t CSSNodeListCount(CSSNodeListRef list) {
|
||||
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
|
||||
return list->count;
|
||||
}
|
||||
|
||||
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
|
||||
void CSSNodeListAdd(const CSSNodeListRef list, const CSSNodeRef node) {
|
||||
CSSNodeListInsert(list, node, list->count);
|
||||
}
|
||||
|
||||
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
|
||||
void CSSNodeListInsert(const CSSNodeListRef list, const CSSNodeRef node, const uint32_t index) {
|
||||
if (list->count == list->capacity) {
|
||||
list->capacity *= 2;
|
||||
list->items = realloc(list->items, sizeof(void *) * list->capacity);
|
||||
@@ -55,8 +55,8 @@ void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
|
||||
list->items[index] = node;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
|
||||
CSSNodeRef removed = list->items[index];
|
||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index) {
|
||||
const CSSNodeRef removed = list->items[index];
|
||||
list->items[index] = NULL;
|
||||
|
||||
for (uint32_t i = index; i < list->count - 1; i++) {
|
||||
@@ -68,7 +68,7 @@ CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
|
||||
return removed;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
|
||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node) {
|
||||
for (uint32_t i = 0; i < list->count; i++) {
|
||||
if (list->items[i] == node) {
|
||||
return CSSNodeListRemove(list, i);
|
||||
@@ -78,6 +78,6 @@ CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) {
|
||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index) {
|
||||
return list->items[index];
|
||||
}
|
||||
|
Reference in New Issue
Block a user