Fossil SCM
Performance optimizations in the markdown formatter.
Commit
ef41fbfa598dd7fa1fb48593d4e5edd266dc95c4184ea66c30df4f377c8131e3
Parent
48c47e1eb7d3012…
2 files changed
+1
-1
+12
-2
+1
-1
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -311,11 +311,11 @@ | ||
| 311 | 311 | pBlob->aData[pBlob->nUsed] = 0; /* Blobs are always nul-terminated */ |
| 312 | 312 | } |
| 313 | 313 | void blob_append(Blob *pBlob, const char *aData, int nData){ |
| 314 | 314 | sqlite3_int64 nUsed; |
| 315 | 315 | assert( aData!=0 || nData==0 ); |
| 316 | - blob_is_init(pBlob); | |
| 316 | + /* blob_is_init(pBlob); // omitted for speed */ | |
| 317 | 317 | if( nData<=0 || pBlob->nUsed + nData >= pBlob->nAlloc ){ |
| 318 | 318 | blob_append_full(pBlob, aData, nData); |
| 319 | 319 | return; |
| 320 | 320 | } |
| 321 | 321 | nUsed = pBlob->nUsed; |
| 322 | 322 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -311,11 +311,11 @@ | |
| 311 | pBlob->aData[pBlob->nUsed] = 0; /* Blobs are always nul-terminated */ |
| 312 | } |
| 313 | void blob_append(Blob *pBlob, const char *aData, int nData){ |
| 314 | sqlite3_int64 nUsed; |
| 315 | assert( aData!=0 || nData==0 ); |
| 316 | blob_is_init(pBlob); |
| 317 | if( nData<=0 || pBlob->nUsed + nData >= pBlob->nAlloc ){ |
| 318 | blob_append_full(pBlob, aData, nData); |
| 319 | return; |
| 320 | } |
| 321 | nUsed = pBlob->nUsed; |
| 322 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -311,11 +311,11 @@ | |
| 311 | pBlob->aData[pBlob->nUsed] = 0; /* Blobs are always nul-terminated */ |
| 312 | } |
| 313 | void blob_append(Blob *pBlob, const char *aData, int nData){ |
| 314 | sqlite3_int64 nUsed; |
| 315 | assert( aData!=0 || nData==0 ); |
| 316 | /* blob_is_init(pBlob); // omitted for speed */ |
| 317 | if( nData<=0 || pBlob->nUsed + nData >= pBlob->nAlloc ){ |
| 318 | blob_append_full(pBlob, aData, nData); |
| 319 | return; |
| 320 | } |
| 321 | nUsed = pBlob->nUsed; |
| 322 |
+12
-2
| --- src/markdown.c | ||
| +++ src/markdown.c | ||
| @@ -1334,11 +1334,16 @@ | ||
| 1334 | 1334 | int level = 0; |
| 1335 | 1335 | char *work_data = data; |
| 1336 | 1336 | size_t work_size = 0; |
| 1337 | 1337 | |
| 1338 | 1338 | while( i<size ){ |
| 1339 | - for(end=i+1; end<size && data[end-1]!='\n'; end++); | |
| 1339 | + char *zEnd = memchr(data+i, '\n', size-i-1); | |
| 1340 | + end = zEnd==0 ? size : (int)(zEnd - (data-1)); | |
| 1341 | + /* The above is the same as: | |
| 1342 | + ** for(end=i+1; end<size && data[end-1]!='\n'; end++); | |
| 1343 | + ** "end" is left with a value such that data[end] is one byte | |
| 1344 | + ** past the first '\n' or one byte past the end of the string */ | |
| 1340 | 1345 | if( is_empty(data+i, size-i) |
| 1341 | 1346 | || (level = is_headerline(data+i, size-i))!= 0 |
| 1342 | 1347 | ){ |
| 1343 | 1348 | break; |
| 1344 | 1349 | } |
| @@ -1402,11 +1407,16 @@ | ||
| 1402 | 1407 | size_t beg, end, pre; |
| 1403 | 1408 | struct Blob *work = new_work_buffer(rndr); |
| 1404 | 1409 | |
| 1405 | 1410 | beg = 0; |
| 1406 | 1411 | while( beg<size ){ |
| 1407 | - for(end=beg+1; end<size && data[end-1]!='\n'; end++); | |
| 1412 | + char *zEnd = memchr(data+beg, '\n', size-beg-1); | |
| 1413 | + end = zEnd==0 ? size : (int)(zEnd - (data-1)); | |
| 1414 | + /* The above is the same as: | |
| 1415 | + ** for(end=beg+1; end<size && data[end-1]!='\n'; end++); | |
| 1416 | + ** "end" is left with a value such that data[end] is one byte | |
| 1417 | + ** past the first \n or past then end of the string. */ | |
| 1408 | 1418 | pre = prefix_code(data+beg, end-beg); |
| 1409 | 1419 | if( pre ){ |
| 1410 | 1420 | beg += pre; /* skipping prefix */ |
| 1411 | 1421 | }else if( !is_empty(data+beg, end-beg) ){ |
| 1412 | 1422 | /* non-empty non-prefixed line breaks the pre */ |
| 1413 | 1423 |
| --- src/markdown.c | |
| +++ src/markdown.c | |
| @@ -1334,11 +1334,16 @@ | |
| 1334 | int level = 0; |
| 1335 | char *work_data = data; |
| 1336 | size_t work_size = 0; |
| 1337 | |
| 1338 | while( i<size ){ |
| 1339 | for(end=i+1; end<size && data[end-1]!='\n'; end++); |
| 1340 | if( is_empty(data+i, size-i) |
| 1341 | || (level = is_headerline(data+i, size-i))!= 0 |
| 1342 | ){ |
| 1343 | break; |
| 1344 | } |
| @@ -1402,11 +1407,16 @@ | |
| 1402 | size_t beg, end, pre; |
| 1403 | struct Blob *work = new_work_buffer(rndr); |
| 1404 | |
| 1405 | beg = 0; |
| 1406 | while( beg<size ){ |
| 1407 | for(end=beg+1; end<size && data[end-1]!='\n'; end++); |
| 1408 | pre = prefix_code(data+beg, end-beg); |
| 1409 | if( pre ){ |
| 1410 | beg += pre; /* skipping prefix */ |
| 1411 | }else if( !is_empty(data+beg, end-beg) ){ |
| 1412 | /* non-empty non-prefixed line breaks the pre */ |
| 1413 |
| --- src/markdown.c | |
| +++ src/markdown.c | |
| @@ -1334,11 +1334,16 @@ | |
| 1334 | int level = 0; |
| 1335 | char *work_data = data; |
| 1336 | size_t work_size = 0; |
| 1337 | |
| 1338 | while( i<size ){ |
| 1339 | char *zEnd = memchr(data+i, '\n', size-i-1); |
| 1340 | end = zEnd==0 ? size : (int)(zEnd - (data-1)); |
| 1341 | /* The above is the same as: |
| 1342 | ** for(end=i+1; end<size && data[end-1]!='\n'; end++); |
| 1343 | ** "end" is left with a value such that data[end] is one byte |
| 1344 | ** past the first '\n' or one byte past the end of the string */ |
| 1345 | if( is_empty(data+i, size-i) |
| 1346 | || (level = is_headerline(data+i, size-i))!= 0 |
| 1347 | ){ |
| 1348 | break; |
| 1349 | } |
| @@ -1402,11 +1407,16 @@ | |
| 1407 | size_t beg, end, pre; |
| 1408 | struct Blob *work = new_work_buffer(rndr); |
| 1409 | |
| 1410 | beg = 0; |
| 1411 | while( beg<size ){ |
| 1412 | char *zEnd = memchr(data+beg, '\n', size-beg-1); |
| 1413 | end = zEnd==0 ? size : (int)(zEnd - (data-1)); |
| 1414 | /* The above is the same as: |
| 1415 | ** for(end=beg+1; end<size && data[end-1]!='\n'; end++); |
| 1416 | ** "end" is left with a value such that data[end] is one byte |
| 1417 | ** past the first \n or past then end of the string. */ |
| 1418 | pre = prefix_code(data+beg, end-beg); |
| 1419 | if( pre ){ |
| 1420 | beg += pre; /* skipping prefix */ |
| 1421 | }else if( !is_empty(data+beg, end-beg) ){ |
| 1422 | /* non-empty non-prefixed line breaks the pre */ |
| 1423 |