summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vlib/counter.c9
-rw-r--r--src/vppinfra/vec.h15
2 files changed, 18 insertions, 6 deletions
diff --git a/src/vlib/counter.c b/src/vlib/counter.c
index adf667f4051..81c81aea02f 100644
--- a/src/vlib/counter.c
+++ b/src/vlib/counter.c
@@ -140,12 +140,9 @@ int
/* Trivially OK, and proves that index >= vec_len(...) */
if (index < vec_len (cm->counters[i]))
continue;
- if (_vec_resize_will_expand
- (cm->counters[i],
- index - vec_len (cm->counters[i]) /* length_increment */ ,
- sizeof (cm->counters[i]) /* data_bytes */ ,
- 0 /* header_bytes */ ,
- CLIB_CACHE_LINE_BYTES /* data_alignment */ ))
+ if (vec_resize_will_expand (cm->counters[i],
+ index - vec_len (cm->counters[i]) +
+ 1 /* length_increment */))
{
vlib_stats_pop_heap (cm, oldheap, index,
3 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ );
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h
index 1fcb5f1a374..e8146af7098 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -209,6 +209,21 @@ _vec_resize_will_expand (void *v,
return 1;
}
+/** \brief Determine if vector will resize with next allocation
+
+ @param V pointer to a vector
+ @param N number of elements to add
+ @return 1 if vector will resize 0 otherwise
+*/
+
+#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).