Fossil SCM
Minor optimization within <code>getAllTicketFields()</code> function.
Commit
c3e7ed308900482e761dda2be1a1319c541f9da852bc9474aba2db5493c97a7c
Parent
0f4a0fe82a3f80b…
1 file changed
+10
-6
+10
-6
| --- src/tkt.c | ||
| +++ src/tkt.c | ||
| @@ -78,24 +78,27 @@ | ||
| 78 | 78 | ** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and |
| 79 | 79 | ** TICKETCHANGE tables exist, respectively. |
| 80 | 80 | */ |
| 81 | 81 | static void getAllTicketFields(void){ |
| 82 | 82 | Stmt q; |
| 83 | - int i, noRegularMimetype, noBaselines; | |
| 83 | + int i, noRegularMimetype, nBaselines; | |
| 84 | 84 | static int once = 0; |
| 85 | 85 | if( once ) return; |
| 86 | - once = noBaselines = 1; | |
| 86 | + once = 1; | |
| 87 | + nBaselines = 0; | |
| 87 | 88 | db_prepare(&q, "PRAGMA table_info(ticket)"); |
| 88 | 89 | while( db_step(&q)==SQLITE_ROW ){ |
| 89 | 90 | const char *zFieldName = db_column_text(&q, 1); |
| 90 | 91 | haveTicket = 1; |
| 91 | 92 | if( memcmp(zFieldName,"tkt_",4)==0 ){ |
| 92 | 93 | if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1; |
| 93 | 94 | continue; |
| 94 | 95 | } |
| 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 | + } | |
| 97 | 100 | continue; |
| 98 | 101 | } |
| 99 | 102 | if( strchr(zFieldName,' ')!=0 ) continue; |
| 100 | 103 | if( nField%10==0 ){ |
| 101 | 104 | aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) ); |
| @@ -104,19 +107,20 @@ | ||
| 104 | 107 | aField[nField].zName = mprintf("%s", zFieldName); |
| 105 | 108 | aField[nField].mUsed = USEDBY_TICKET; |
| 106 | 109 | nField++; |
| 107 | 110 | } |
| 108 | 111 | db_finalize(&q); |
| 109 | - if( !noBaselines ){ | |
| 112 | + if( nBaselines ){ | |
| 110 | 113 | db_prepare(&q, "SELECT 1 FROM pragma_table_info('ticket') " |
| 111 | 114 | "WHERE type = 'INTEGER' AND name = :n"); |
| 112 | - for(i=0; i<nField; i++){ | |
| 115 | + for(i=0; i<nField && nBaselines!=0; i++){ | |
| 113 | 116 | char *zBsln = mprintf("baseline for %s",aField[i].zName); |
| 114 | 117 | db_bind_text(&q, ":n", zBsln); |
| 115 | 118 | if( db_step(&q)==SQLITE_ROW ){ |
| 116 | 119 | aField[i].zBsln = zBsln; |
| 117 | 120 | nTicketBslns++; |
| 121 | + nBaselines--; | |
| 118 | 122 | }else{ |
| 119 | 123 | free(zBsln); |
| 120 | 124 | } |
| 121 | 125 | db_reset(&q); |
| 122 | 126 | } |
| 123 | 127 |
| --- 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 |