1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-14 18:36:40 +00:00

chunker: get rid of read_buf

if we have a OS file handle, we can directly read to the final destination - one memcpy less.
if we have a Python file object, we get a Python bytes object as read result (can't save the memcpy here).
This commit is contained in:
Thomas Waldmann 2015-05-31 18:41:23 +02:00
parent 926454c0d8
commit 072326fef0

View file

@ -79,7 +79,7 @@ typedef struct {
int window_size, chunk_mask, min_size;
size_t buf_size;
uint32_t *table;
uint8_t *data, *read_buf;
uint8_t *data;
PyObject *fd;
int fh;
int done, eof;
@ -96,7 +96,6 @@ chunker_init(int window_size, int chunk_mask, int min_size, int max_size, uint32
c->table = buzhash_init_table(seed);
c->buf_size = max_size;
c->data = malloc(c->buf_size);
c->read_buf = malloc(c->buf_size);
return c;
}
@ -122,7 +121,6 @@ chunker_free(Chunker *c)
Py_XDECREF(c->fd);
free(c->table);
free(c->data);
free(c->read_buf);
free(c);
}
@ -140,9 +138,8 @@ chunker_fill(Chunker *c)
}
if(c->fh >= 0) {
// if we have a os-level file descriptor, use os-level API
n = read(c->fh, c->read_buf, n);
n = read(c->fh, c->data + c->position + c->remaining, n);
if(n > 0) {
memcpy(c->data + c->position + c->remaining, c->read_buf, n);
c->remaining += n;
c->bytes_read += n;
}