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

[PATCH v2 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_guarantee_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 usage for this helper IMHO can be ssh_buffer_pack_va,
which could interate once more at the beginning to determine the amount
of data that will be added.

Thanks,

----
Changes since v1:
- ssh_buffer_ensure_allocated -> ssh_buffer_guarantee_allocated
- reindent ssh_buffer_guarantee_allocated

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

 include/libssh/buffer.h |   1 +
 src/agent.c             |  15 +++++
 src/buffer.c            |  27 +++++++++
 src/dh.c                |  12 ++++
 src/pcap.c              |  12 ++++
 src/sftp.c              | 124 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 191 insertions(+)

-- 
2.17.1


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