summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/vec.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-03-17 18:59:46 +0100
committerDamjan Marion <dmarion@me.com>2022-03-18 13:16:36 +0000
commit66d4cb5a217d556aa7bd2471f02a39badb6d5cd2 (patch)
tree53d4333bed2cdfc16e5e1d5858e6a70fab9bc1ca /src/vppinfra/vec.h
parent05563c9a904b6bb862ba783dc3519c8415bf9cf5 (diff)
vppinfra: refactor *_will_expand() functions
Type: refactor Change-Id: I3625eacf9e04542ca8778df5d46075a8654642c7 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/vec.h')
-rw-r--r--src/vppinfra/vec.h37
1 files changed, 5 insertions, 32 deletions
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h
index 3f50bd25625..7e4cc0f8959 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -184,26 +184,14 @@ _vec_resize_inline (void *v,
*/
always_inline int
-_vec_resize_will_expand (void *v,
- word length_increment,
- uword data_bytes, uword header_bytes,
- uword data_align)
+_vec_resize_will_expand (void *v, uword n_elts, uword elt_size)
{
- uword new_data_bytes, aligned_header_bytes;
-
- aligned_header_bytes = vec_header_bytes (header_bytes);
-
- new_data_bytes = data_bytes + aligned_header_bytes;
-
if (PREDICT_TRUE (v != 0))
{
- void *p = v - aligned_header_bytes;
-
/* Vector header must start heap object. */
- ASSERT (clib_mem_is_heap_object (p));
+ ASSERT (clib_mem_is_heap_object (vec_header (v)));
- /* Typically we'll not need to resize. */
- if (new_data_bytes <= clib_mem_size (p))
+ if (vec_mem_size (v) >= ((_vec_len (v) + n_elts)) * elt_size)
return 0;
}
return 1;
@@ -217,22 +205,7 @@ _vec_resize_will_expand (void *v,
*/
#define vec_resize_will_expand(V, N) \
- ({ \
- word _v (n) = (N); \
- word _v (l) = vec_len (V); \
- _vec_resize_will_expand ((V), _v (n), \
- (_v (l) + _v (n)) * sizeof ((V)[0]), 0, 0); \
- })
-
-/** \brief Predicate function, says whether the supplied vector is a clib heap
- object (general version).
-
- @param v pointer to a vector
- @param header_bytes vector header size in bytes (may be zero)
- @return 0 or 1
-*/
-uword clib_mem_is_vec_h (void *v, uword header_bytes);
-
+ _vec_resize_will_expand (V, N, sizeof ((V)[0]))
/** \brief Predicate function, says whether the supplied vector is a clib heap
object
@@ -243,7 +216,7 @@ uword clib_mem_is_vec_h (void *v, uword header_bytes);
always_inline uword
clib_mem_is_vec (void *v)
{
- return clib_mem_is_vec_h (v, 0);
+ return clib_mem_is_heap_object (vec_header (v));
}
/* Local variable naming macro (prevents collisions with other macro naming). */