X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fvec.h;h=a029630559c4763650079753fa170227802eb737;hb=eb987d3a09f669787014b1553f032219522149e1;hp=eed96d6b9c2608aac25f97e77293e8a866148769;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h index eed96d6b9c2..a029630559c 100644 --- a/src/vppinfra/vec.h +++ b/src/vppinfra/vec.h @@ -145,6 +145,42 @@ _vec_resize (void *v, data_align)); } +/** \brief Determine if vector will resize with next allocation + + @param v pointer to a vector + @param length_increment length increment in elements + @param data_bytes requested size in bytes + @param header_bytes header size in bytes (may be zero) + @param data_align alignment (may be zero) + @return 1 if vector will resize 0 otherwise +*/ + +always_inline int +_vec_resize_will_expand (void *v, + word length_increment, + uword data_bytes, uword header_bytes, + uword data_align) +{ + 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)); + + /* Typically we'll not need to resize. */ + if (new_data_bytes <= clib_mem_size (p)) + return 0; + } + return 1; +} + /** \brief Predicate function, says whether the supplied vector is a clib heap object (general version). @@ -375,6 +411,8 @@ do { \ #define vec_validate_ha(V,I,H,A) \ do { \ + STATIC_ASSERT(A==0 || ((A % sizeof(V[0]))==0) || ((sizeof(V[0]) % A) == 0),\ + "vector validate aligned on incorrectly sized object"); \ word _v(i) = (I); \ word _v(l) = vec_len (V); \ if (_v(i) >= _v(l)) \ @@ -455,7 +493,7 @@ do { \ @param A alignment (may be zero) @return V (value-result macro parameter) */ -#define vec_validate_init_empty_aligned(V,I,A) \ +#define vec_validate_init_empty_aligned(V,I,INIT,A) \ vec_validate_init_empty_ha(V,I,INIT,0,A) /** \brief Add 1 element to end of vector (general version). @@ -903,7 +941,7 @@ do { \ word _v(i) = 0; \ while (_v(i) < vec_len(v)) \ { \ - if (v[_v(i)] == E) \ + if ((v)[_v(i)] == E) \ break; \ _v(i)++; \ } \