以下两个代码块中哪一个总体上更好?
一个返回语句,更多缩进代码:
struct dnode *dllist_push_front(struct dllist *dllist, void *data)
{
struct dnode *dnode = malloc(sizeof(struct dnode));
if (dnode) {
dnode->data = data;
dnode->next = dllist->sentinel->next;
dnode->prev = dlllist->sentinel;
dnode->next->prev = dnode;
dllist->sentinel->next = dnode;
dllist->size++;
}
return dnode;
}
或者,
两个返回语句,缩进较少的代码:
struct dnode *dllist_push_front(struct dllist *dllist, void *data)
{
struct dnode *dnode = malloc (sizeof(struct dnode));
if (!dnode)
return NULL;
dnode->data = data;
dnode->next = dllist->sentinel->next;
dnode->prev = dlllist->sentinel;
dnode->next->prev = dnode;
dllist->sentinel->next = dnode;
dllist->size++;
return dnode;
}