Fossil SCM

Minor optimization within <code>getAllTicketFields()</code> function.

george 2022-08-29 14:03 deltify-tkt-blobs
Commit c3e7ed308900482e761dda2be1a1319c541f9da852bc9474aba2db5493c97a7c
1 file changed +10 -6
+10 -6
--- src/tkt.c
+++ src/tkt.c
@@ -78,24 +78,27 @@
7878
** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
7979
** TICKETCHANGE tables exist, respectively.
8080
*/
8181
static void getAllTicketFields(void){
8282
Stmt q;
83
- int i, noRegularMimetype, noBaselines;
83
+ int i, noRegularMimetype, nBaselines;
8484
static int once = 0;
8585
if( once ) return;
86
- once = noBaselines = 1;
86
+ once = 1;
87
+ nBaselines = 0;
8788
db_prepare(&q, "PRAGMA table_info(ticket)");
8889
while( db_step(&q)==SQLITE_ROW ){
8990
const char *zFieldName = db_column_text(&q, 1);
9091
haveTicket = 1;
9192
if( memcmp(zFieldName,"tkt_",4)==0 ){
9293
if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
9394
continue;
9495
}
95
- if( noBaselines && memcmp(zFieldName,"baseline for ",13)==0 ){
96
- noBaselines = 0;
96
+ if( memcmp(zFieldName,"baseline for ",13)==0 ){
97
+ if( strcmp(db_column_text(&q,2),"INTEGER")==0 ){
98
+ nBaselines++;
99
+ }
97100
continue;
98101
}
99102
if( strchr(zFieldName,' ')!=0 ) continue;
100103
if( nField%10==0 ){
101104
aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
@@ -104,19 +107,20 @@
104107
aField[nField].zName = mprintf("%s", zFieldName);
105108
aField[nField].mUsed = USEDBY_TICKET;
106109
nField++;
107110
}
108111
db_finalize(&q);
109
- if( !noBaselines ){
112
+ if( nBaselines ){
110113
db_prepare(&q, "SELECT 1 FROM pragma_table_info('ticket') "
111114
"WHERE type = 'INTEGER' AND name = :n");
112
- for(i=0; i<nField; i++){
115
+ for(i=0; i<nField && nBaselines!=0; i++){
113116
char *zBsln = mprintf("baseline for %s",aField[i].zName);
114117
db_bind_text(&q, ":n", zBsln);
115118
if( db_step(&q)==SQLITE_ROW ){
116119
aField[i].zBsln = zBsln;
117120
nTicketBslns++;
121
+ nBaselines--;
118122
}else{
119123
free(zBsln);
120124
}
121125
db_reset(&q);
122126
}
123127
--- src/tkt.c
+++ src/tkt.c
@@ -78,24 +78,27 @@
78 ** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
79 ** TICKETCHANGE tables exist, respectively.
80 */
81 static void getAllTicketFields(void){
82 Stmt q;
83 int i, noRegularMimetype, noBaselines;
84 static int once = 0;
85 if( once ) return;
86 once = noBaselines = 1;
 
87 db_prepare(&q, "PRAGMA table_info(ticket)");
88 while( db_step(&q)==SQLITE_ROW ){
89 const char *zFieldName = db_column_text(&q, 1);
90 haveTicket = 1;
91 if( memcmp(zFieldName,"tkt_",4)==0 ){
92 if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
93 continue;
94 }
95 if( noBaselines && memcmp(zFieldName,"baseline for ",13)==0 ){
96 noBaselines = 0;
 
 
97 continue;
98 }
99 if( strchr(zFieldName,' ')!=0 ) continue;
100 if( nField%10==0 ){
101 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
@@ -104,19 +107,20 @@
104 aField[nField].zName = mprintf("%s", zFieldName);
105 aField[nField].mUsed = USEDBY_TICKET;
106 nField++;
107 }
108 db_finalize(&q);
109 if( !noBaselines ){
110 db_prepare(&q, "SELECT 1 FROM pragma_table_info('ticket') "
111 "WHERE type = 'INTEGER' AND name = :n");
112 for(i=0; i<nField; i++){
113 char *zBsln = mprintf("baseline for %s",aField[i].zName);
114 db_bind_text(&q, ":n", zBsln);
115 if( db_step(&q)==SQLITE_ROW ){
116 aField[i].zBsln = zBsln;
117 nTicketBslns++;
 
118 }else{
119 free(zBsln);
120 }
121 db_reset(&q);
122 }
123
--- src/tkt.c
+++ src/tkt.c
@@ -78,24 +78,27 @@
78 ** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
79 ** TICKETCHANGE tables exist, respectively.
80 */
81 static void getAllTicketFields(void){
82 Stmt q;
83 int i, noRegularMimetype, nBaselines;
84 static int once = 0;
85 if( once ) return;
86 once = 1;
87 nBaselines = 0;
88 db_prepare(&q, "PRAGMA table_info(ticket)");
89 while( db_step(&q)==SQLITE_ROW ){
90 const char *zFieldName = db_column_text(&q, 1);
91 haveTicket = 1;
92 if( memcmp(zFieldName,"tkt_",4)==0 ){
93 if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
94 continue;
95 }
96 if( memcmp(zFieldName,"baseline for ",13)==0 ){
97 if( strcmp(db_column_text(&q,2),"INTEGER")==0 ){
98 nBaselines++;
99 }
100 continue;
101 }
102 if( strchr(zFieldName,' ')!=0 ) continue;
103 if( nField%10==0 ){
104 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
@@ -104,19 +107,20 @@
107 aField[nField].zName = mprintf("%s", zFieldName);
108 aField[nField].mUsed = USEDBY_TICKET;
109 nField++;
110 }
111 db_finalize(&q);
112 if( nBaselines ){
113 db_prepare(&q, "SELECT 1 FROM pragma_table_info('ticket') "
114 "WHERE type = 'INTEGER' AND name = :n");
115 for(i=0; i<nField && nBaselines!=0; i++){
116 char *zBsln = mprintf("baseline for %s",aField[i].zName);
117 db_bind_text(&q, ":n", zBsln);
118 if( db_step(&q)==SQLITE_ROW ){
119 aField[i].zBsln = zBsln;
120 nTicketBslns++;
121 nBaselines--;
122 }else{
123 free(zBsln);
124 }
125 db_reset(&q);
126 }
127

Keyboard Shortcuts

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