Fossil SCM

Various small performance enhancements.

drh 2009-08-27 18:33 trunk
Commit 4c37130fde6b2e84f367343afa2f9ae4ae103c2e
+17 -2
--- src/blob.c
+++ src/blob.c
@@ -79,12 +79,27 @@
7979
/*
8080
** We find that the built-in isspace() function does not work for
8181
** some international character sets. So here is a substitute.
8282
*/
8383
static int blob_isspace(char c){
84
- return c==' ' || c=='\n' || c=='\t' ||
85
- c=='\r' || c=='\f' || c=='\v';
84
+ return c==' ' || (c<='\r' && c>='\t');
85
+}
86
+
87
+/*
88
+** COMMAND: test-isspace
89
+*/
90
+void isspace_cmd(void){
91
+ int i;
92
+ for(i=0; i<=255; i++){
93
+ if( i==' ' || i=='\n' || i=='\t' || i=='\v'
94
+ || i=='\f' || i=='\r' ){
95
+ assert( blob_isspace((char)i) );
96
+ }else{
97
+ assert( !blob_isspace((char)i) );
98
+ }
99
+ }
100
+ printf("All 256 characters OK\n");
86101
}
87102
88103
/*
89104
** This routine is called if a blob operation fails because we
90105
** have run out of memory.
91106
--- src/blob.c
+++ src/blob.c
@@ -79,12 +79,27 @@
79 /*
80 ** We find that the built-in isspace() function does not work for
81 ** some international character sets. So here is a substitute.
82 */
83 static int blob_isspace(char c){
84 return c==' ' || c=='\n' || c=='\t' ||
85 c=='\r' || c=='\f' || c=='\v';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86 }
87
88 /*
89 ** This routine is called if a blob operation fails because we
90 ** have run out of memory.
91
--- src/blob.c
+++ src/blob.c
@@ -79,12 +79,27 @@
79 /*
80 ** We find that the built-in isspace() function does not work for
81 ** some international character sets. So here is a substitute.
82 */
83 static int blob_isspace(char c){
84 return c==' ' || (c<='\r' && c>='\t');
85 }
86
87 /*
88 ** COMMAND: test-isspace
89 */
90 void isspace_cmd(void){
91 int i;
92 for(i=0; i<=255; i++){
93 if( i==' ' || i=='\n' || i=='\t' || i=='\v'
94 || i=='\f' || i=='\r' ){
95 assert( blob_isspace((char)i) );
96 }else{
97 assert( !blob_isspace((char)i) );
98 }
99 }
100 printf("All 256 characters OK\n");
101 }
102
103 /*
104 ** This routine is called if a blob operation fails because we
105 ** have run out of memory.
106
+23 -13
--- src/content.c
+++ src/content.c
@@ -149,18 +149,36 @@
149149
}
150150
db_finalize(&q);
151151
}
152152
bag_clear(&pending);
153153
}
154
+
155
+/*
156
+** Get the blob.content value for blob.rid=rid. Return 1 on success or
157
+** 0 on failure.
158
+*/
159
+static int content_of_blob(int rid, Blob *pBlob){
160
+ static Stmt q;
161
+ int rc = 0;
162
+ db_static_prepare(&q, "SELECT content FROM blob WHERE rid=:rid AND size>=0");
163
+ db_bind_int(&q, ":rid", rid);
164
+ if( db_step(&q)==SQLITE_ROW ){
165
+ db_ephemeral_blob(&q, 0, pBlob);
166
+ blob_uncompress(pBlob, pBlob);
167
+ rc = 1;
168
+ }
169
+ db_reset(&q);
170
+ return rc;
171
+}
172
+
154173
155174
/*
156175
** Extract the content for ID rid and put it into the
157176
** uninitialized blob. Return 1 on success. If the record
158177
** is a phantom, zero pBlob and return 0.
159178
*/
160179
int content_get(int rid, Blob *pBlob){
161
- Stmt q;
162180
Blob src;
163181
int srcid;
164182
int rc = 0;
165183
int i;
166184
static Bag inProcess;
@@ -183,11 +201,11 @@
183201
blob_zero(&contentCache.a[i].content);
184202
contentCache.n--;
185203
if( i<contentCache.n ){
186204
contentCache.a[i] = contentCache.a[contentCache.n];
187205
}
188
- CONTENT_TRACE(("%*shit cache: %d\n",
206
+ CONTENT_TRACE(("%*scache: %d\n",
189207
bag_count(&inProcess), "", rid))
190208
return 1;
191209
}
192210
}
193211
@@ -210,21 +228,17 @@
210228
return 0;
211229
}
212230
bag_insert(&inProcess, srcid);
213231
214232
if( content_get(srcid, &src) ){
215
- db_prepare(&q, "SELECT content FROM blob WHERE rid=%d AND size>=0", rid);
216
- if( db_step(&q)==SQLITE_ROW ){
217
- Blob delta;
218
- db_ephemeral_blob(&q, 0, &delta);
219
- blob_uncompress(&delta, &delta);
233
+ Blob delta;
234
+ if( content_of_blob(rid, &delta) ){
220235
blob_init(pBlob,0,0);
221236
blob_delta_apply(&src, &delta, pBlob);
222237
blob_reset(&delta);
223238
rc = 1;
224239
}
225
- db_finalize(&q);
226240
227241
/* Save the srcid artifact in the cache */
228242
if( contentCache.n<MX_CACHE_CNT ){
229243
i = contentCache.n++;
230244
}else if( ((contentCache.skipCnt++)%EXPELL_INTERVAL)!=0 ){
@@ -254,17 +268,13 @@
254268
}
255269
}
256270
bag_remove(&inProcess, srcid);
257271
}else{
258272
/* No delta required. Read content directly from the database */
259
- db_prepare(&q, "SELECT content FROM blob WHERE rid=%d AND size>=0", rid);
260
- if( db_step(&q)==SQLITE_ROW ){
261
- db_ephemeral_blob(&q, 0, pBlob);
262
- blob_uncompress(pBlob, pBlob);
273
+ if( content_of_blob(rid, pBlob) ){
263274
rc = 1;
264275
}
265
- db_finalize(&q);
266276
}
267277
if( rc==0 ){
268278
bag_insert(&contentCache.missing, rid);
269279
}else{
270280
bag_insert(&contentCache.available, rid);
271281
--- src/content.c
+++ src/content.c
@@ -149,18 +149,36 @@
149 }
150 db_finalize(&q);
151 }
152 bag_clear(&pending);
153 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
155 /*
156 ** Extract the content for ID rid and put it into the
157 ** uninitialized blob. Return 1 on success. If the record
158 ** is a phantom, zero pBlob and return 0.
159 */
160 int content_get(int rid, Blob *pBlob){
161 Stmt q;
162 Blob src;
163 int srcid;
164 int rc = 0;
165 int i;
166 static Bag inProcess;
@@ -183,11 +201,11 @@
183 blob_zero(&contentCache.a[i].content);
184 contentCache.n--;
185 if( i<contentCache.n ){
186 contentCache.a[i] = contentCache.a[contentCache.n];
187 }
188 CONTENT_TRACE(("%*shit cache: %d\n",
189 bag_count(&inProcess), "", rid))
190 return 1;
191 }
192 }
193
@@ -210,21 +228,17 @@
210 return 0;
211 }
212 bag_insert(&inProcess, srcid);
213
214 if( content_get(srcid, &src) ){
215 db_prepare(&q, "SELECT content FROM blob WHERE rid=%d AND size>=0", rid);
216 if( db_step(&q)==SQLITE_ROW ){
217 Blob delta;
218 db_ephemeral_blob(&q, 0, &delta);
219 blob_uncompress(&delta, &delta);
220 blob_init(pBlob,0,0);
221 blob_delta_apply(&src, &delta, pBlob);
222 blob_reset(&delta);
223 rc = 1;
224 }
225 db_finalize(&q);
226
227 /* Save the srcid artifact in the cache */
228 if( contentCache.n<MX_CACHE_CNT ){
229 i = contentCache.n++;
230 }else if( ((contentCache.skipCnt++)%EXPELL_INTERVAL)!=0 ){
@@ -254,17 +268,13 @@
254 }
255 }
256 bag_remove(&inProcess, srcid);
257 }else{
258 /* No delta required. Read content directly from the database */
259 db_prepare(&q, "SELECT content FROM blob WHERE rid=%d AND size>=0", rid);
260 if( db_step(&q)==SQLITE_ROW ){
261 db_ephemeral_blob(&q, 0, pBlob);
262 blob_uncompress(pBlob, pBlob);
263 rc = 1;
264 }
265 db_finalize(&q);
266 }
267 if( rc==0 ){
268 bag_insert(&contentCache.missing, rid);
269 }else{
270 bag_insert(&contentCache.available, rid);
271
--- src/content.c
+++ src/content.c
@@ -149,18 +149,36 @@
149 }
150 db_finalize(&q);
151 }
152 bag_clear(&pending);
153 }
154
155 /*
156 ** Get the blob.content value for blob.rid=rid. Return 1 on success or
157 ** 0 on failure.
158 */
159 static int content_of_blob(int rid, Blob *pBlob){
160 static Stmt q;
161 int rc = 0;
162 db_static_prepare(&q, "SELECT content FROM blob WHERE rid=:rid AND size>=0");
163 db_bind_int(&q, ":rid", rid);
164 if( db_step(&q)==SQLITE_ROW ){
165 db_ephemeral_blob(&q, 0, pBlob);
166 blob_uncompress(pBlob, pBlob);
167 rc = 1;
168 }
169 db_reset(&q);
170 return rc;
171 }
172
173
174 /*
175 ** Extract the content for ID rid and put it into the
176 ** uninitialized blob. Return 1 on success. If the record
177 ** is a phantom, zero pBlob and return 0.
178 */
179 int content_get(int rid, Blob *pBlob){
 
180 Blob src;
181 int srcid;
182 int rc = 0;
183 int i;
184 static Bag inProcess;
@@ -183,11 +201,11 @@
201 blob_zero(&contentCache.a[i].content);
202 contentCache.n--;
203 if( i<contentCache.n ){
204 contentCache.a[i] = contentCache.a[contentCache.n];
205 }
206 CONTENT_TRACE(("%*scache: %d\n",
207 bag_count(&inProcess), "", rid))
208 return 1;
209 }
210 }
211
@@ -210,21 +228,17 @@
228 return 0;
229 }
230 bag_insert(&inProcess, srcid);
231
232 if( content_get(srcid, &src) ){
233 Blob delta;
234 if( content_of_blob(rid, &delta) ){
 
 
 
235 blob_init(pBlob,0,0);
236 blob_delta_apply(&src, &delta, pBlob);
237 blob_reset(&delta);
238 rc = 1;
239 }
 
240
241 /* Save the srcid artifact in the cache */
242 if( contentCache.n<MX_CACHE_CNT ){
243 i = contentCache.n++;
244 }else if( ((contentCache.skipCnt++)%EXPELL_INTERVAL)!=0 ){
@@ -254,17 +268,13 @@
268 }
269 }
270 bag_remove(&inProcess, srcid);
271 }else{
272 /* No delta required. Read content directly from the database */
273 if( content_of_blob(rid, pBlob) ){
 
 
 
274 rc = 1;
275 }
 
276 }
277 if( rc==0 ){
278 bag_insert(&contentCache.missing, rid);
279 }else{
280 bag_insert(&contentCache.available, rid);
281
+13 -4
--- src/encode.c
+++ src/encode.c
@@ -423,10 +423,18 @@
423423
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 64, 64, 64, 64, 64, 64,
424424
64, 10, 11, 12, 13, 14, 15, 64, 64, 1, 64, 64, 1, 64, 64, 0,
425425
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
426426
64, 10, 11, 12, 13, 14, 15, 64, 64, 1, 64, 64, 1, 64, 64, 0,
427427
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
428
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
429
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
430
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
431
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
432
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
433
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
434
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
435
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
428436
};
429437
430438
/*
431439
** Decode a N-character base-16 number into base-256. N must be a
432440
** multiple of 2. The output buffer must be at least N/2 characters
@@ -450,14 +458,15 @@
450458
/*
451459
** Return true if the input string contains only valid base-16 digits.
452460
** If any invalid characters appear in the string, return false.
453461
*/
454462
int validate16(const char *zIn, int nIn){
455
- int c, i;
456
- for(i=0; i<nIn && (c = zIn[i])!=0; i++){
457
- if( c & ~0x7f ) return 0;
458
- if( zDecode[c]>63 ) return 0;
463
+ int i;
464
+ for(i=0; i<nIn; i++, zIn++){
465
+ if( zDecode[zIn[0]&0xff]>63 ){
466
+ return zIn[0]==0;
467
+ }
459468
}
460469
return 1;
461470
}
462471
463472
/*
464473
--- src/encode.c
+++ src/encode.c
@@ -423,10 +423,18 @@
423 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 64, 64, 64, 64, 64, 64,
424 64, 10, 11, 12, 13, 14, 15, 64, 64, 1, 64, 64, 1, 64, 64, 0,
425 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
426 64, 10, 11, 12, 13, 14, 15, 64, 64, 1, 64, 64, 1, 64, 64, 0,
427 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
 
 
 
 
 
 
 
428 };
429
430 /*
431 ** Decode a N-character base-16 number into base-256. N must be a
432 ** multiple of 2. The output buffer must be at least N/2 characters
@@ -450,14 +458,15 @@
450 /*
451 ** Return true if the input string contains only valid base-16 digits.
452 ** If any invalid characters appear in the string, return false.
453 */
454 int validate16(const char *zIn, int nIn){
455 int c, i;
456 for(i=0; i<nIn && (c = zIn[i])!=0; i++){
457 if( c & ~0x7f ) return 0;
458 if( zDecode[c]>63 ) return 0;
 
459 }
460 return 1;
461 }
462
463 /*
464
--- src/encode.c
+++ src/encode.c
@@ -423,10 +423,18 @@
423 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 64, 64, 64, 64, 64, 64,
424 64, 10, 11, 12, 13, 14, 15, 64, 64, 1, 64, 64, 1, 64, 64, 0,
425 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
426 64, 10, 11, 12, 13, 14, 15, 64, 64, 1, 64, 64, 1, 64, 64, 0,
427 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
428 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
429 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
430 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
431 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
432 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
433 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
434 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
435 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
436 };
437
438 /*
439 ** Decode a N-character base-16 number into base-256. N must be a
440 ** multiple of 2. The output buffer must be at least N/2 characters
@@ -450,14 +458,15 @@
458 /*
459 ** Return true if the input string contains only valid base-16 digits.
460 ** If any invalid characters appear in the string, return false.
461 */
462 int validate16(const char *zIn, int nIn){
463 int i;
464 for(i=0; i<nIn; i++, zIn++){
465 if( zDecode[zIn[0]&0xff]>63 ){
466 return zIn[0]==0;
467 }
468 }
469 return 1;
470 }
471
472 /*
473
--- src/rebuild.c
+++ src/rebuild.c
@@ -206,10 +206,11 @@
206206
char *zTable;
207207
208208
bag_init(&bagDone);
209209
ttyOutput = doOut;
210210
processCnt = 0;
211
+ printf("0 (0%%)...\r"); fflush(stdout);
211212
db_multi_exec(zSchemaUpdates);
212213
for(;;){
213214
zTable = db_text(0,
214215
"SELECT name FROM sqlite_master"
215216
" WHERE type='table'"
216217
--- src/rebuild.c
+++ src/rebuild.c
@@ -206,10 +206,11 @@
206 char *zTable;
207
208 bag_init(&bagDone);
209 ttyOutput = doOut;
210 processCnt = 0;
 
211 db_multi_exec(zSchemaUpdates);
212 for(;;){
213 zTable = db_text(0,
214 "SELECT name FROM sqlite_master"
215 " WHERE type='table'"
216
--- src/rebuild.c
+++ src/rebuild.c
@@ -206,10 +206,11 @@
206 char *zTable;
207
208 bag_init(&bagDone);
209 ttyOutput = doOut;
210 processCnt = 0;
211 printf("0 (0%%)...\r"); fflush(stdout);
212 db_multi_exec(zSchemaUpdates);
213 for(;;){
214 zTable = db_text(0,
215 "SELECT name FROM sqlite_master"
216 " WHERE type='table'"
217

Keyboard Shortcuts

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