Browse Source

revert toBuffer() changes

v1.x
Tj Holowaychuk 14 years ago
parent
commit
3a74a43351
  1. 28
      src/Canvas.cc

28
src/Canvas.cc

@ -109,27 +109,17 @@ static cairo_status_t
toBuffer(void *c, const uint8_t *data, unsigned len) { toBuffer(void *c, const uint8_t *data, unsigned len) {
closure_t *closure = (closure_t *) c; closure_t *closure = (closure_t *) c;
// Olaf (2011-02-21): Store more data, but don't call realloc() on every chunk. if (closure->len) {
// Also, keep track of how much memory is used closure->data = (uint8_t *) realloc(closure->data, closure->len + len);
if (closure->len + len > closure->max_len) { if (!closure->data) return CAIRO_STATUS_NO_MEMORY;
uint8_t * new_data;
unsigned new_max_len = closure->max_len;
// Round up the buffer size to be a multiple of 1024 bytes.
new_max_len = (closure->max_len + len + 1023) & ~1023;
new_data = (uint8_t *) realloc(closure->data, new_max_len);
if (new_data == NULL) return CAIRO_STATUS_NO_MEMORY;
// Keep track of how much more memory we just allocated.
V8::AdjustAmountOfExternalAllocatedMemory(new_max_len - closure->max_len);
closure->data = new_data;
closure->max_len = new_max_len;
}
memcpy(closure->data + closure->len, data, len); memcpy(closure->data + closure->len, data, len);
closure->len += len; closure->len += len;
} else {
closure->data = (uint8_t *) malloc(len);
if (!closure->data) return CAIRO_STATUS_NO_MEMORY;
memcpy(closure->data, data, len);
closure->len += len;
}
return CAIRO_STATUS_SUCCESS; return CAIRO_STATUS_SUCCESS;
} }

Loading…
Cancel
Save