]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move extend out of users_file.c to sbuff.c
authorAlan T. DeKok <aland@freeradius.org>
Wed, 1 Nov 2023 19:20:21 +0000 (15:20 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 1 Nov 2023 19:20:21 +0000 (15:20 -0400)
If we're processing substantial amounts of input in a loop,
it doesn't help to extend the buffer by 32 bytes at a time.
Doing so will help decrease the calls to "extend", and ensures
that the application no longer needs to manually extend the
buffers.

src/lib/server/users_file.c
src/lib/util/sbuff.c

index e490fa075a6f431474eeff27238076760d3bfc82..3dc9faee280f20ddbbea0b3becf9b6dcdfd93e8a 100644 (file)
@@ -303,8 +303,6 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR
                bool            leading_spaces;
                PAIR_LIST       *t;
 
-               fr_sbuff_extend_lowat(NULL, &sbuff, 1024);
-
                /*
                 *      If the line is empty or has only comments,
                 *      then we don't care about leading spaces.
@@ -393,8 +391,6 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR
                comma = false;
 
 check_item:
-               fr_sbuff_extend_lowat(NULL, &sbuff, 1024);
-
                /*
                 *      Skip spaces before the item, and allow the
                 *      check list to end on comment or LF.
@@ -527,8 +523,6 @@ setup_reply:
                comma = false;
 
 reply_item:
-               fr_sbuff_extend_lowat(NULL, &sbuff, 1024);
-
                /*
                 *      Reply items start with spaces.  If there's no
                 *      spaces, then the current entry is done.  Add
index 133b56a4d104965f3ab84859f6e0c477732752be..bc3269fe1a0930cad024d0215ecdaa86537c0afa 100644 (file)
@@ -700,7 +700,7 @@ size_t fr_sbuff_out_bstrncpy(fr_sbuff_t *out, fr_sbuff_t *in, size_t len)
 
                remaining = (len - fr_sbuff_used_total(&our_in));
 
-               if (!fr_sbuff_extend(&our_in)) break;
+               if (!fr_sbuff_extend_lowat(NULL, &our_in, 32)) break;
 
                chunk_len = fr_sbuff_remaining(&our_in);
                if (chunk_len > remaining) chunk_len = remaining;
@@ -741,7 +741,7 @@ ssize_t fr_sbuff_out_bstrncpy_exact(fr_sbuff_t *out, fr_sbuff_t *in, size_t len)
                ssize_t copied;
 
                remaining = (len - fr_sbuff_used_total(&our_in));
-               if (remaining && !fr_sbuff_extend(&our_in)) return 0;
+               if (remaining && !fr_sbuff_extend_lowat(NULL, &our_in, 32)) return 0;
 
                chunk_len = fr_sbuff_remaining(&our_in);
                if (chunk_len > remaining) chunk_len = remaining;
@@ -788,7 +788,7 @@ size_t fr_sbuff_out_bstrncpy_allowed(fr_sbuff_t *out, fr_sbuff_t *in, size_t len
                char    *p;
                char    *end;
 
-               if (!fr_sbuff_extend(&our_in)) break;
+               if (!fr_sbuff_extend_lowat(NULL, &our_in, 32)) break;
 
                p = fr_sbuff_current(&our_in);
                end = CONSTRAINED_END(&our_in, len, fr_sbuff_used_total(&our_in));
@@ -1748,7 +1748,7 @@ size_t fr_sbuff_adv_past_allowed(fr_sbuff_t *sbuff, size_t len, bool
        while (total < len) {
                char *end;
 
-               if (!fr_sbuff_extend(sbuff)) break;
+               if (!fr_sbuff_extend_lowat(NULL, sbuff, 32)) break;
 
                end = CONSTRAINED_END(sbuff, len, total);
                p = sbuff->p;
@@ -1923,7 +1923,7 @@ char *fr_sbuff_adv_to_chr(fr_sbuff_t *sbuff, size_t len, char c)
                char const      *found;
                char            *end;
 
-               if (!fr_sbuff_extend(&our_sbuff)) break;
+               if (!fr_sbuff_extend_lowat(NULL, &our_sbuff, 32)) break;
 
                end = CONSTRAINED_END(sbuff, len, total);
                found = memchr(our_sbuff.p, c, end - our_sbuff.p);