Fossil SCM
Added blob_reserve() for use with a manifest-generation optimization.
Commit
972cc5f9ac23a8dcd465886a726332400db7df64d95335eee702d7ef9265369a
Parent
39262b420a38906…
1 file changed
+12
+12
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -477,10 +477,22 @@ | ||
| 477 | 477 | void blob_resize(Blob *pBlob, unsigned int newSize){ |
| 478 | 478 | pBlob->xRealloc(pBlob, newSize+1); |
| 479 | 479 | pBlob->nUsed = newSize; |
| 480 | 480 | pBlob->aData[newSize] = 0; |
| 481 | 481 | } |
| 482 | + | |
| 483 | +/* | |
| 484 | +** Ensures that the given blob has at least the given amount of memory | |
| 485 | +** allocated to it. Does not modify pBlob->nUsed nor will it reduce | |
| 486 | +** the currently-allocated amount of memory. | |
| 487 | +*/ | |
| 488 | +void blob_reserve(Blob *pBlob, unsigned int newSize){ | |
| 489 | + if(newSize>pBlob->nUsed){ | |
| 490 | + pBlob->xRealloc(pBlob, newSize); | |
| 491 | + pBlob->aData[newSize] = 0; | |
| 492 | + } | |
| 493 | +} | |
| 482 | 494 | |
| 483 | 495 | /* |
| 484 | 496 | ** Make sure a blob is nul-terminated and is not a pointer to unmanaged |
| 485 | 497 | ** space. Return a pointer to the data. |
| 486 | 498 | */ |
| 487 | 499 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -477,10 +477,22 @@ | |
| 477 | void blob_resize(Blob *pBlob, unsigned int newSize){ |
| 478 | pBlob->xRealloc(pBlob, newSize+1); |
| 479 | pBlob->nUsed = newSize; |
| 480 | pBlob->aData[newSize] = 0; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | ** Make sure a blob is nul-terminated and is not a pointer to unmanaged |
| 485 | ** space. Return a pointer to the data. |
| 486 | */ |
| 487 |
| --- src/blob.c | |
| +++ src/blob.c | |
| @@ -477,10 +477,22 @@ | |
| 477 | void blob_resize(Blob *pBlob, unsigned int newSize){ |
| 478 | pBlob->xRealloc(pBlob, newSize+1); |
| 479 | pBlob->nUsed = newSize; |
| 480 | pBlob->aData[newSize] = 0; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | ** Ensures that the given blob has at least the given amount of memory |
| 485 | ** allocated to it. Does not modify pBlob->nUsed nor will it reduce |
| 486 | ** the currently-allocated amount of memory. |
| 487 | */ |
| 488 | void blob_reserve(Blob *pBlob, unsigned int newSize){ |
| 489 | if(newSize>pBlob->nUsed){ |
| 490 | pBlob->xRealloc(pBlob, newSize); |
| 491 | pBlob->aData[newSize] = 0; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | ** Make sure a blob is nul-terminated and is not a pointer to unmanaged |
| 497 | ** space. Return a pointer to the data. |
| 498 | */ |
| 499 |