Pavel Chromy: performance tweak of gdb_put_packet_inner() removing malloc and avoiding memcpy of larger blocks of data,
git-svn-id: svn://svn.berlios.de/openocd/trunk@453 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
209d7c0edc
commit
652a5b18b4
|
@ -314,31 +314,27 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len)
|
|||
free(debug_buffer);
|
||||
#endif
|
||||
|
||||
void *allocated = NULL;
|
||||
char stackAlloc[1024];
|
||||
char *t = stackAlloc;
|
||||
int totalLen = 1 + len + 1 + 2;
|
||||
if (totalLen > sizeof(stackAlloc))
|
||||
char local_buffer[1024];
|
||||
local_buffer[0] = '$';
|
||||
if (len+4 <= sizeof(local_buffer))
|
||||
{
|
||||
allocated = malloc(totalLen);
|
||||
t = allocated;
|
||||
if (allocated == NULL)
|
||||
{
|
||||
ERROR("Ran out of memory trying to reply packet %d\n", totalLen);
|
||||
exit(-1);
|
||||
/* performance gain on smaller packets by only a single call to gdb_write() */
|
||||
memcpy(local_buffer+1, buffer, len++);
|
||||
local_buffer[len++] = '#';
|
||||
local_buffer[len++] = DIGITS[(my_checksum >> 4) & 0xf];
|
||||
local_buffer[len++] = DIGITS[my_checksum & 0xf];
|
||||
gdb_write(connection, local_buffer, len);
|
||||
}
|
||||
}
|
||||
t[0] = '$';
|
||||
memcpy(t + 1, buffer, len);
|
||||
t[1 + len] = '#';
|
||||
t[1 + len + 1] = DIGITS[(my_checksum >> 4) & 0xf];
|
||||
t[1 + len + 2] = DIGITS[my_checksum & 0xf];
|
||||
|
||||
gdb_write(connection, t, totalLen);
|
||||
|
||||
if (allocated)
|
||||
else
|
||||
{
|
||||
free(allocated);
|
||||
/* larger packets are transmitted directly from caller supplied buffer
|
||||
by several calls to gdb_write() to avoid dynamic allocation */
|
||||
local_buffer[1] = '#';
|
||||
local_buffer[2] = DIGITS[(my_checksum >> 4) & 0xf];
|
||||
local_buffer[3] = DIGITS[my_checksum & 0xf];
|
||||
gdb_write(connection, local_buffer, 1);
|
||||
gdb_write(connection, buffer, len);
|
||||
gdb_write(connection, local_buffer+1, 3);
|
||||
}
|
||||
|
||||
if ((retval = gdb_get_char(connection, &reply)) != ERROR_OK)
|
||||
|
|
Loading…
Reference in New Issue