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
File diff suppressed because it is too large
Load Diff
@@ -123,18 +123,18 @@ typedef void (*CSSPrintFunc)(void *context);
|
||||
|
||||
// CSSNode
|
||||
CSSNodeRef CSSNodeNew();
|
||||
void CSSNodeInit(CSSNodeRef node);
|
||||
void CSSNodeFree(CSSNodeRef node);
|
||||
void CSSNodeInit(const CSSNodeRef node);
|
||||
void CSSNodeFree(const CSSNodeRef node);
|
||||
|
||||
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index);
|
||||
void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child);
|
||||
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index);
|
||||
uint32_t CSSNodeChildCount(CSSNodeRef node);
|
||||
void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index);
|
||||
void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
|
||||
CSSNodeRef CSSNodeGetChild(const CSSNodeRef node, const uint32_t index);
|
||||
uint32_t CSSNodeChildCount(const CSSNodeRef node);
|
||||
|
||||
void CSSNodeCalculateLayout(CSSNodeRef node,
|
||||
float availableWidth,
|
||||
float availableHeight,
|
||||
CSSDirection parentDirection);
|
||||
void CSSNodeCalculateLayout(const CSSNodeRef node,
|
||||
const float availableWidth,
|
||||
const float availableHeight,
|
||||
const CSSDirection parentDirection);
|
||||
|
||||
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
||||
// set.
|
||||
@@ -142,26 +142,26 @@ void CSSNodeCalculateLayout(CSSNodeRef node,
|
||||
// measure functions
|
||||
// depends on information not known to CSSLayout they must perform this dirty
|
||||
// marking manually.
|
||||
void CSSNodeMarkDirty(CSSNodeRef node);
|
||||
bool CSSNodeIsDirty(CSSNodeRef node);
|
||||
void CSSNodeMarkDirty(const CSSNodeRef node);
|
||||
bool CSSNodeIsDirty(const CSSNodeRef node);
|
||||
|
||||
void CSSNodePrint(CSSNodeRef node, CSSPrintOptions options);
|
||||
void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options);
|
||||
|
||||
bool CSSValueIsUndefined(float value);
|
||||
bool CSSValueIsUndefined(const float value);
|
||||
|
||||
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeSet##name(CSSNodeRef node, type paramName); \
|
||||
type CSSNodeGet##name(CSSNodeRef node);
|
||||
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeSet##name(const CSSNodeRef node, type paramName); \
|
||||
type CSSNodeGet##name(const CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeStyleSet##name(CSSNodeRef node, type paramName); \
|
||||
type CSSNodeStyleGet##name(CSSNodeRef node);
|
||||
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeStyleSet##name(const CSSNodeRef node, const type paramName); \
|
||||
type CSSNodeStyleGet##name(const CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeStyleSet##name(CSSNodeRef node, CSSEdge edge, type paramName); \
|
||||
type CSSNodeStyleGet##name(CSSNodeRef node, CSSEdge edge);
|
||||
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeStyleSet##name(const CSSNodeRef node, const CSSEdge edge, const type paramName); \
|
||||
type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge);
|
||||
|
||||
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(CSSNodeRef node);
|
||||
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(const CSSNodeRef node);
|
||||
|
||||
CSS_NODE_PROPERTY(void *, Context, context);
|
||||
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
||||
|
@@ -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];
|
||||
}
|
||||
|
@@ -21,13 +21,13 @@ CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct CSSNodeList *CSSNodeListRef;
|
||||
|
||||
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity);
|
||||
void CSSNodeListFree(CSSNodeListRef list);
|
||||
uint32_t CSSNodeListCount(CSSNodeListRef list);
|
||||
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node);
|
||||
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, uint32_t index);
|
||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
|
||||
void CSSNodeListFree(const CSSNodeListRef list);
|
||||
uint32_t CSSNodeListCount(const CSSNodeListRef list);
|
||||
void CSSNodeListAdd(const CSSNodeListRef list, const CSSNodeRef node);
|
||||
void CSSNodeListInsert(const CSSNodeListRef list, const CSSNodeRef node, const uint32_t index);
|
||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
|
||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
|
||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
|
||||
|
||||
CSS_EXTERN_C_END
|
||||
|
Reference in New Issue
Block a user