Use pre-allocated scratch area, rather than constantly-reallocated scratch area.
This commit is contained in:
parent
b8ec48d179
commit
43f42cbb4c
@ -195,6 +195,12 @@ typedef struct guac_terminal_delta {
|
|||||||
*/
|
*/
|
||||||
guac_terminal_operation* operations;
|
guac_terminal_operation* operations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scratch area of same size as the operations buffer, facilitating copies
|
||||||
|
* of overlapping regions.
|
||||||
|
*/
|
||||||
|
guac_terminal_operation* scratch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the screen, in characters.
|
* The width of the screen, in characters.
|
||||||
*/
|
*/
|
||||||
|
@ -580,14 +580,18 @@ guac_terminal_delta* guac_terminal_delta_alloc(int width, int height) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Alloc scratch area */
|
||||||
|
delta->scratch = malloc(width * height * sizeof(guac_terminal_operation));
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void guac_terminal_delta_free(guac_terminal_delta* delta) {
|
void guac_terminal_delta_free(guac_terminal_delta* delta) {
|
||||||
|
|
||||||
/* Free operations buffer */
|
/* Free operations buffers */
|
||||||
free(delta->operations);
|
free(delta->operations);
|
||||||
|
free(delta->scratch);
|
||||||
|
|
||||||
/* Free delta */
|
/* Free delta */
|
||||||
free(delta);
|
free(delta);
|
||||||
@ -620,16 +624,14 @@ void guac_terminal_delta_copy(guac_terminal_delta* delta,
|
|||||||
|
|
||||||
/* FIXME: Handle intersections between src and dst rects */
|
/* FIXME: Handle intersections between src and dst rects */
|
||||||
|
|
||||||
guac_terminal_operation* src_copy = malloc(
|
memcpy(delta->scratch, delta->operations,
|
||||||
sizeof(guac_terminal_operation) * delta->width * delta->height);
|
|
||||||
memcpy(src_copy, delta->operations,
|
|
||||||
sizeof(guac_terminal_operation) * delta->width * delta->height);
|
sizeof(guac_terminal_operation) * delta->width * delta->height);
|
||||||
|
|
||||||
guac_terminal_operation* current_row =
|
guac_terminal_operation* current_row =
|
||||||
&(delta->operations[dst_row*delta->width + dst_column]);
|
&(delta->operations[dst_row*delta->width + dst_column]);
|
||||||
|
|
||||||
guac_terminal_operation* src_current_row =
|
guac_terminal_operation* src_current_row =
|
||||||
&(src_copy[src_row*delta->width + src_column]);
|
&(delta->scratch[src_row*delta->width + src_column]);
|
||||||
|
|
||||||
/* Set rectangle to copy operations */
|
/* Set rectangle to copy operations */
|
||||||
for (row=0; row<h; row++) {
|
for (row=0; row<h; row++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user