summaryrefslogtreecommitdiff
path: root/compll.c
diff options
context:
space:
mode:
Diffstat (limited to 'compll.c')
-rw-r--r--compll.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/compll.c b/compll.c
index 13d1ca0..a1b8324 100644
--- a/compll.c
+++ b/compll.c
@@ -88,7 +88,7 @@ struct ablock *ablocks = NULL;
struct ublock *ublocks = NULL;
/* number of ablock entries in the ablocks array */
-int ablocks_size = 0;
+int ablocks_size = 0, ablocks_last = 0;
/* a static buffer used to write temporary compression data to */
unsigned char *compress_buf = NULL;
@@ -178,19 +178,14 @@ static int block_alloc() {
/* initialize the data with zeroes */
memset(ublocks[ub].data, 0, conf_blocksize);
- /* get a new slot in the ablocks array.
- * TODO: looping through the ablocks array can be slow, we could cache the
- * index to the first unused slot to significantly lower the number of
- * iterations in normal cases (though the worst case will still be a
- * full pass through the array) */
- for(ab=0; ab<ablocks_size; ab++)
- if(ablocks[ab].data == NULL && ablocks[ab].ublock == -1)
- break;
+ /* get the first unused slot in the ablocks array. Items in the array are
+ * never deallocated or removed and are allocated sequentially. */
+ ab = ablocks_last++;
- /* no free slot found? increase the ablocks array.
+ /* Is the array too small to hold the new item? allocate more memory.
* The first time the array is allocated it is large anough for 64 blocks,
* each time it has to be grown the size is multiplied with 1.5 */
- if(ab == ablocks_size) {
+ if(ab >= ablocks_size) {
if(ab == 0) {
ablocks_size = 64;
if((ablocks = malloc(ablocks_size * sizeof(struct ablock))) == NULL)