Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8ad4d8

Browse files
committed
Constify the arguments of ilist.c/h functions
Const qualifiers ensure that we don't do something stupid in thefunction implementation. Additionally they clarify the interface. Asan example: void slist_delete(slist_head *head, const slist_node *node)Here one can instantly tell that node->next is not going to be set toNULL. Finally, const qualifiers potentially allow the compiler to domore optimizations. This being said, no benchmarking was done forthis patch.The functions that return non-const pointers like slist_next_node(),dclist_next_node() etc. are not affected by the patch intentionally.Author: Aleksander AlekseevReviewed-by: Andres FreundDiscussion:https://postgr.es/m/CAJ7c6TM2%3D08mNKD9aJg8vEY9hd%2BG4L7%2BNvh30UiNT3kShgRgNg%40mail.gmail.com
1 parent881fa86 commitc8ad4d8

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

‎src/backend/lib/ilist.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Caution: this is O(n); consider using slist_delete_current() instead.
2929
*/
3030
void
31-
slist_delete(slist_head*head,slist_node*node)
31+
slist_delete(slist_head*head,constslist_node*node)
3232
{
3333
slist_node*last=&head->head;
3434
slist_node*cur;
@@ -57,7 +57,7 @@ slist_delete(slist_head *head, slist_node *node)
5757
*Validate that 'node' is a member of 'head'
5858
*/
5959
void
60-
dlist_member_check(dlist_head*head,dlist_node*node)
60+
dlist_member_check(constdlist_head*head,constdlist_node*node)
6161
{
6262
dlist_iteriter;
6363

@@ -73,7 +73,7 @@ dlist_member_check(dlist_head *head, dlist_node *node)
7373
* Verify integrity of a doubly linked list
7474
*/
7575
void
76-
dlist_check(dlist_head*head)
76+
dlist_check(constdlist_head*head)
7777
{
7878
dlist_node*cur;
7979

@@ -110,7 +110,7 @@ dlist_check(dlist_head *head)
110110
* Verify integrity of a singly linked list
111111
*/
112112
void
113-
slist_check(slist_head*head)
113+
slist_check(constslist_head*head)
114114
{
115115
slist_node*cur;
116116

‎src/include/lib/ilist.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ typedef struct slist_mutable_iter
286286
/* Prototypes for functions too big to be inline */
287287

288288
/* Caution: this is O(n); consider using slist_delete_current() instead */
289-
externvoidslist_delete(slist_head*head,slist_node*node);
289+
externvoidslist_delete(slist_head*head,constslist_node*node);
290290

291291
#ifdefILIST_DEBUG
292-
externvoiddlist_member_check(dlist_head*head,dlist_node*node);
293-
externvoiddlist_check(dlist_head*head);
294-
externvoidslist_check(slist_head*head);
292+
externvoiddlist_member_check(constdlist_head*head,constdlist_node*node);
293+
externvoiddlist_check(constdlist_head*head);
294+
externvoidslist_check(constslist_head*head);
295295
#else
296296
/*
297297
* These seemingly useless casts to void are here to keep the compiler quiet
@@ -322,7 +322,7 @@ dlist_init(dlist_head *head)
322322
* An empty list has either its first 'next' pointer set to NULL, or to itself.
323323
*/
324324
staticinlinebool
325-
dlist_is_empty(dlist_head*head)
325+
dlist_is_empty(constdlist_head*head)
326326
{
327327
dlist_check(head);
328328

@@ -465,7 +465,7 @@ dlist_move_tail(dlist_head *head, dlist_node *node)
465465
* Caution: unreliable if 'node' is not in the list.
466466
*/
467467
staticinlinebool
468-
dlist_has_next(dlist_head*head,dlist_node*node)
468+
dlist_has_next(constdlist_head*head,constdlist_node*node)
469469
{
470470
returnnode->next!=&head->head;
471471
}
@@ -475,7 +475,7 @@ dlist_has_next(dlist_head *head, dlist_node *node)
475475
* Caution: unreliable if 'node' is not in the list.
476476
*/
477477
staticinlinebool
478-
dlist_has_prev(dlist_head*head,dlist_node*node)
478+
dlist_has_prev(constdlist_head*head,constdlist_node*node)
479479
{
480480
returnnode->prev!=&head->head;
481481
}
@@ -629,7 +629,7 @@ dclist_init(dclist_head *head)
629629
*Returns true if the list is empty, otherwise false.
630630
*/
631631
staticinlinebool
632-
dclist_is_empty(dclist_head*head)
632+
dclist_is_empty(constdclist_head*head)
633633
{
634634
Assert(dlist_is_empty(&head->dlist)== (head->count==0));
635635
return (head->count==0);
@@ -773,7 +773,7 @@ dclist_move_tail(dclist_head *head, dlist_node *node)
773773
* Caution: 'node' must be a member of 'head'.
774774
*/
775775
staticinlinebool
776-
dclist_has_next(dclist_head*head,dlist_node*node)
776+
dclist_has_next(constdclist_head*head,constdlist_node*node)
777777
{
778778
dlist_member_check(&head->dlist,node);
779779
Assert(head->count>0);
@@ -788,7 +788,7 @@ dclist_has_next(dclist_head *head, dlist_node *node)
788788
* Caution: 'node' must be a member of 'head'.
789789
*/
790790
staticinlinebool
791-
dclist_has_prev(dclist_head*head,dlist_node*node)
791+
dclist_has_prev(constdclist_head*head,constdlist_node*node)
792792
{
793793
dlist_member_check(&head->dlist,node);
794794
Assert(head->count>0);
@@ -866,7 +866,7 @@ dclist_tail_node(dclist_head *head)
866866
*Returns the stored number of entries in 'head'
867867
*/
868868
staticinlineuint32
869-
dclist_count(dclist_head*head)
869+
dclist_count(constdclist_head*head)
870870
{
871871
Assert(dlist_is_empty(&head->dlist)== (head->count==0));
872872

@@ -929,7 +929,7 @@ slist_init(slist_head *head)
929929
* Is the list empty?
930930
*/
931931
staticinlinebool
932-
slist_is_empty(slist_head*head)
932+
slist_is_empty(constslist_head*head)
933933
{
934934
slist_check(head);
935935

@@ -977,7 +977,7 @@ slist_pop_head_node(slist_head *head)
977977
* Check whether 'node' has a following node.
978978
*/
979979
staticinlinebool
980-
slist_has_next(slist_head*head,slist_node*node)
980+
slist_has_next(constslist_head*head,constslist_node*node)
981981
{
982982
slist_check(head);
983983

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp