From 43f42cbb4cf68c01075ec4df72211e3285cb2992 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 5 Apr 2013 13:15:19 -0700 Subject: [PATCH] Use pre-allocated scratch area, rather than constantly-reallocated scratch area. --- protocols/ssh/include/terminal.h | 6 ++++++ protocols/ssh/src/terminal.c | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/protocols/ssh/include/terminal.h b/protocols/ssh/include/terminal.h index 2b831f40..1f07ee49 100644 --- a/protocols/ssh/include/terminal.h +++ b/protocols/ssh/include/terminal.h @@ -195,6 +195,12 @@ typedef struct guac_terminal_delta { */ 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. */ diff --git a/protocols/ssh/src/terminal.c b/protocols/ssh/src/terminal.c index 656c05bf..40d72cfa 100644 --- a/protocols/ssh/src/terminal.c +++ b/protocols/ssh/src/terminal.c @@ -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; } void guac_terminal_delta_free(guac_terminal_delta* delta) { - /* Free operations buffer */ + /* Free operations buffers */ free(delta->operations); + free(delta->scratch); /* 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 */ - guac_terminal_operation* src_copy = malloc( - sizeof(guac_terminal_operation) * delta->width * delta->height); - memcpy(src_copy, delta->operations, + memcpy(delta->scratch, delta->operations, sizeof(guac_terminal_operation) * delta->width * delta->height); guac_terminal_operation* current_row = &(delta->operations[dst_row*delta->width + dst_column]); 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 */ for (row=0; row