]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove single use isc_buffer_putdecint() function
authorOndřej Surý <ondrej@isc.org>
Thu, 15 Dec 2022 21:15:37 +0000 (22:15 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 20 Dec 2022 18:13:48 +0000 (19:13 +0100)
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.

lib/dns/catz.c
lib/isc/buffer.c
lib/isc/include/isc/buffer.h

index 03704555e8c3a8df38ae38722899cd49f16c4b76..600a9bb345d79b4f69caf7cd71d1ceb380d86f33 100644 (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, "; ");
        }
index 0cd4a24ee8af38ca2f726b483155a04913d1626d..c1630bfdb681945dcada6754e587b8b5747bd19c 100644 (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;
index 71a03db11d97c5e8cba1cc832376abc13fe94efc..6247a89456c94f81296dd0d1b0af269fc66734f7 100644 (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);
 /*!<