Fossil SCM

Simplification to the PQueue object to remove the content pointer, which is never used.

drh 2024-02-08 01:33 trunk
Commit 83c4ab60517e4bca2171dd62c15a6d93d1de7d6c4c5e80f8a1f15f33765d2b2a
2 files changed +2 -6 +3 -3
+2 -6
--- src/pqueue.c
+++ src/pqueue.c
@@ -42,11 +42,10 @@
4242
struct PQueue {
4343
int cnt; /* Number of entries in the queue */
4444
int sz; /* Number of slots in a[] */
4545
struct QueueElement {
4646
int id; /* ID of the element */
47
- void *p; /* Content pointer */
4847
double value; /* Value of element. Kept in ascending order */
4948
} *a;
5049
};
5150
#endif
5251
@@ -74,11 +73,11 @@
7473
}
7574
7675
/*
7776
** Insert element e into the queue.
7877
*/
79
-void pqueuex_insert(PQueue *p, int e, double v, void *pData){
78
+void pqueuex_insert(PQueue *p, int e, double v){
8079
int i, j;
8180
if( p->cnt+1>p->sz ){
8281
pqueuex_resize(p, p->cnt+5);
8382
}
8483
for(i=0; i<p->cnt; i++){
@@ -88,29 +87,26 @@
8887
}
8988
break;
9089
}
9190
}
9291
p->a[i].id = e;
93
- p->a[i].p = pData;
9492
p->a[i].value = v;
9593
p->cnt++;
9694
}
9795
9896
/*
9997
** Extract the first element from the queue (the element with
10098
** the smallest value) and return its ID. Return 0 if the queue
10199
** is empty.
102100
*/
103
-int pqueuex_extract(PQueue *p, void **pp){
101
+int pqueuex_extract(PQueue *p){
104102
int e, i;
105103
if( p->cnt==0 ){
106
- if( pp ) *pp = 0;
107104
return 0;
108105
}
109106
e = p->a[0].id;
110
- if( pp ) *pp = p->a[0].p;
111107
for(i=0; i<p->cnt-1; i++){
112108
p->a[i] = p->a[i+1];
113109
}
114110
p->cnt--;
115111
return e;
116112
}
117113
--- src/pqueue.c
+++ src/pqueue.c
@@ -42,11 +42,10 @@
42 struct PQueue {
43 int cnt; /* Number of entries in the queue */
44 int sz; /* Number of slots in a[] */
45 struct QueueElement {
46 int id; /* ID of the element */
47 void *p; /* Content pointer */
48 double value; /* Value of element. Kept in ascending order */
49 } *a;
50 };
51 #endif
52
@@ -74,11 +73,11 @@
74 }
75
76 /*
77 ** Insert element e into the queue.
78 */
79 void pqueuex_insert(PQueue *p, int e, double v, void *pData){
80 int i, j;
81 if( p->cnt+1>p->sz ){
82 pqueuex_resize(p, p->cnt+5);
83 }
84 for(i=0; i<p->cnt; i++){
@@ -88,29 +87,26 @@
88 }
89 break;
90 }
91 }
92 p->a[i].id = e;
93 p->a[i].p = pData;
94 p->a[i].value = v;
95 p->cnt++;
96 }
97
98 /*
99 ** Extract the first element from the queue (the element with
100 ** the smallest value) and return its ID. Return 0 if the queue
101 ** is empty.
102 */
103 int pqueuex_extract(PQueue *p, void **pp){
104 int e, i;
105 if( p->cnt==0 ){
106 if( pp ) *pp = 0;
107 return 0;
108 }
109 e = p->a[0].id;
110 if( pp ) *pp = p->a[0].p;
111 for(i=0; i<p->cnt-1; i++){
112 p->a[i] = p->a[i+1];
113 }
114 p->cnt--;
115 return e;
116 }
117
--- src/pqueue.c
+++ src/pqueue.c
@@ -42,11 +42,10 @@
42 struct PQueue {
43 int cnt; /* Number of entries in the queue */
44 int sz; /* Number of slots in a[] */
45 struct QueueElement {
46 int id; /* ID of the element */
 
47 double value; /* Value of element. Kept in ascending order */
48 } *a;
49 };
50 #endif
51
@@ -74,11 +73,11 @@
73 }
74
75 /*
76 ** Insert element e into the queue.
77 */
78 void pqueuex_insert(PQueue *p, int e, double v){
79 int i, j;
80 if( p->cnt+1>p->sz ){
81 pqueuex_resize(p, p->cnt+5);
82 }
83 for(i=0; i<p->cnt; i++){
@@ -88,29 +87,26 @@
87 }
88 break;
89 }
90 }
91 p->a[i].id = e;
 
92 p->a[i].value = v;
93 p->cnt++;
94 }
95
96 /*
97 ** Extract the first element from the queue (the element with
98 ** the smallest value) and return its ID. Return 0 if the queue
99 ** is empty.
100 */
101 int pqueuex_extract(PQueue *p){
102 int e, i;
103 if( p->cnt==0 ){
 
104 return 0;
105 }
106 e = p->a[0].id;
 
107 for(i=0; i<p->cnt-1; i++){
108 p->a[i] = p->a[i+1];
109 }
110 p->cnt--;
111 return e;
112 }
113
+3 -3
--- src/tag.c
+++ src/tag.c
@@ -44,11 +44,11 @@
4444
Stmt ins; /* INSERT INTO tagxref */
4545
Stmt eventupdate; /* UPDATE event */
4646
4747
assert( tagType==0 || tagType==2 );
4848
pqueuex_init(&queue);
49
- pqueuex_insert(&queue, pid, 0.0, 0);
49
+ pqueuex_insert(&queue, pid, 0.0);
5050
5151
/* Query for children of :pid to which to propagate the tag.
5252
** Three returns: (1) rid of the child. (2) timestamp of child.
5353
** (3) True to propagate or false to block.
5454
*/
@@ -79,18 +79,18 @@
7979
if( tagid==TAG_BGCOLOR ){
8080
db_prepare(&eventupdate,
8181
"UPDATE event SET bgcolor=%Q WHERE objid=:rid", zValue
8282
);
8383
}
84
- while( (pid = pqueuex_extract(&queue, 0))!=0 ){
84
+ while( (pid = pqueuex_extract(&queue))!=0 ){
8585
db_bind_int(&s, ":pid", pid);
8686
while( db_step(&s)==SQLITE_ROW ){
8787
int doit = db_column_int(&s, 2);
8888
if( doit ){
8989
int cid = db_column_int(&s, 0);
9090
double mtime = db_column_double(&s, 1);
91
- pqueuex_insert(&queue, cid, mtime, 0);
91
+ pqueuex_insert(&queue, cid, mtime);
9292
db_bind_int(&ins, ":rid", cid);
9393
db_step(&ins);
9494
db_reset(&ins);
9595
if( tagid==TAG_BGCOLOR ){
9696
db_bind_int(&eventupdate, ":rid", cid);
9797
--- src/tag.c
+++ src/tag.c
@@ -44,11 +44,11 @@
44 Stmt ins; /* INSERT INTO tagxref */
45 Stmt eventupdate; /* UPDATE event */
46
47 assert( tagType==0 || tagType==2 );
48 pqueuex_init(&queue);
49 pqueuex_insert(&queue, pid, 0.0, 0);
50
51 /* Query for children of :pid to which to propagate the tag.
52 ** Three returns: (1) rid of the child. (2) timestamp of child.
53 ** (3) True to propagate or false to block.
54 */
@@ -79,18 +79,18 @@
79 if( tagid==TAG_BGCOLOR ){
80 db_prepare(&eventupdate,
81 "UPDATE event SET bgcolor=%Q WHERE objid=:rid", zValue
82 );
83 }
84 while( (pid = pqueuex_extract(&queue, 0))!=0 ){
85 db_bind_int(&s, ":pid", pid);
86 while( db_step(&s)==SQLITE_ROW ){
87 int doit = db_column_int(&s, 2);
88 if( doit ){
89 int cid = db_column_int(&s, 0);
90 double mtime = db_column_double(&s, 1);
91 pqueuex_insert(&queue, cid, mtime, 0);
92 db_bind_int(&ins, ":rid", cid);
93 db_step(&ins);
94 db_reset(&ins);
95 if( tagid==TAG_BGCOLOR ){
96 db_bind_int(&eventupdate, ":rid", cid);
97
--- src/tag.c
+++ src/tag.c
@@ -44,11 +44,11 @@
44 Stmt ins; /* INSERT INTO tagxref */
45 Stmt eventupdate; /* UPDATE event */
46
47 assert( tagType==0 || tagType==2 );
48 pqueuex_init(&queue);
49 pqueuex_insert(&queue, pid, 0.0);
50
51 /* Query for children of :pid to which to propagate the tag.
52 ** Three returns: (1) rid of the child. (2) timestamp of child.
53 ** (3) True to propagate or false to block.
54 */
@@ -79,18 +79,18 @@
79 if( tagid==TAG_BGCOLOR ){
80 db_prepare(&eventupdate,
81 "UPDATE event SET bgcolor=%Q WHERE objid=:rid", zValue
82 );
83 }
84 while( (pid = pqueuex_extract(&queue))!=0 ){
85 db_bind_int(&s, ":pid", pid);
86 while( db_step(&s)==SQLITE_ROW ){
87 int doit = db_column_int(&s, 2);
88 if( doit ){
89 int cid = db_column_int(&s, 0);
90 double mtime = db_column_double(&s, 1);
91 pqueuex_insert(&queue, cid, mtime);
92 db_bind_int(&ins, ":rid", cid);
93 db_step(&ins);
94 db_reset(&ins);
95 if( tagid==TAG_BGCOLOR ){
96 db_bind_int(&eventupdate, ":rid", cid);
97

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button