[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 0/1] RFC: add ssh_buffer_ensure_allocated


Hi,

while profiling libssh, I noticed that in different places ssh_buffer's
were realloc'ed more than once during their lifetime. Since in few cases
the amount of data is known in advance, I added a small helper to make
sure the internal allocated buffer will be large enough to contain all
the data needed. Of course, this is just an optimization to be used when
an amount is known, otherwise there will be an extra allocation.

The downside is that each call to ssh_buffer_ensure_allocated has a
minimal knowledge of the internals of ssh_buffer, e.g. for a string (the
value for its size, then the data of the string itself). Also, a
better/shorter name is welcome too.

An additional uage for this helper IMHO can be ssh_buffer_pack_va, which
could interate once more at te beginning to determine the amount of data
that will be added.

Thanks,

Pino Toscano (1):
  buffer: add and use ssh_buffer_ensure_allocated

 include/libssh/buffer.h |   1 +
 src/agent.c             |  14 +++++
 src/buffer.c            |  25 +++++++++
 src/dh.c                |  12 ++++
 src/pcap.c              |  12 ++++
 src/sftp.c              | 119 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 183 insertions(+)

-- 
2.17.1


Follow-Ups:
[PATCH 1/1] buffer: add and use ssh_buffer_ensure_allocatedPino Toscano <ptoscano@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org