2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Remove single use isc_buffer_putdecint() function

The isc_buffer_putdecint() could be easily replaced with
isc_buffer_printf() with just a small overhead of calling vsnprintf()
twice instead once.  This is not on a hot-path (dns_catz unit), so we
can ignore the overhead and instead have less single-use code in favor
of using reusable more generic function.
This commit is contained in:
Ondřej Surý
2022-12-15 22:15:37 +01:00
parent 2a94123d5b
commit 135ec7a0f0
3 changed files with 1 additions and 39 deletions

View File

@@ -1575,7 +1575,7 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
(apl_ent.family == 2 && apl_ent.prefix < 128))
{
isc_buffer_putuint8(aclb, '/');
isc_buffer_putdecint(aclb, apl_ent.prefix);
isc_buffer_printf(aclb, "%" PRId8, apl_ent.prefix);
}
isc_buffer_putstr(aclb, "; ");
}

View File

@@ -81,29 +81,6 @@ isc_buffer_compact(isc_buffer_t *b) {
b->used = length;
}
void
isc_buffer_putdecint(isc_buffer_t *b, int64_t v) {
unsigned int l = 0;
unsigned char *cp;
char buf[21];
isc_result_t result;
REQUIRE(ISC_BUFFER_VALID(b));
/* xxxwpk do it more low-level way ? */
l = snprintf(buf, 21, "%" PRId64, v);
RUNTIME_CHECK(l <= 21);
if (b->autore) {
result = isc_buffer_reserve(b, l);
REQUIRE(result == ISC_R_SUCCESS);
}
REQUIRE(isc_buffer_availablelength(b) >= l);
cp = isc_buffer_used(b);
memmove(cp, buf, l);
b->used += l;
}
isc_result_t
isc_buffer_dup(isc_mem_t *mctx, isc_buffer_t **dstp, const isc_buffer_t *src) {
isc_buffer_t *dst = NULL;

View File

@@ -420,21 +420,6 @@ isc_buffer_putmem(isc_buffer_t *b, const unsigned char *base,
*\li The used pointer in 'b' is advanced by 'length'.
*/
void
isc_buffer_putdecint(isc_buffer_t *b, int64_t v);
/*!<
* \brief Put decimal representation of 'v' in b
*
* Requires:
*\li 'b' is a valid buffer.
*
*\li The length of the available region of 'b' is at least strlen(dec('v'))
* or the buffer has autoreallocation enabled.
*
* Ensures:
*\li The used pointer in 'b' is advanced by strlen(dec('v')).
*/
isc_result_t
isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r);
/*!<