VectorVal: Embed vector_val

Similar motivation as for RecordVal, save an extra malloc/free
and pointer indirection.

This breaks the `auto& RawVec()` API which previously returned
a reference to the std::vector*. It now returns a reference
to the vector instead. It's commented as intended for internal
and compiled code, so even though it's public API,

The previous `std::vector<std::optional<ZVal>>*&` return type was also very
likely not intended (all consumers just dereference it anyhow). I'm certain
this API was never meant to modify the actual pointer value.

I've switched to explicit typing, too.
This commit is contained in:
Arne Welzel 2023-09-21 15:06:50 +02:00
parent f362935a66
commit cbaf43e8ea
7 changed files with 70 additions and 81 deletions

View file

@ -60,7 +60,7 @@ static bool copy_vec_elem(VectorVal* vv, zeek_uint_t ind, ZVal zv, const TypePtr
if ( vv->Size() <= ind )
vv->Resize(ind + 1);
auto& elem = (*vv->RawVec())[ind];
auto& elem = vv->RawVec()[ind];
if ( ! ZVal::IsManagedType(t) )
{
@ -96,12 +96,12 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
#define VEC_COERCE(tag, lhs_type, cast, rhs_accessor, ov_check, ov_err) \
static VectorVal* vec_coerce_##tag(VectorVal* vec, const ZInst& z) \
{ \
auto& v = *vec->RawVec(); \
auto& v = vec->RawVec(); \
auto yt = make_intrusive<VectorType>(base_type(lhs_type)); \
auto res_zv = new VectorVal(yt); \
auto n = v.size(); \
res_zv->Resize(n); \
auto& res = *res_zv->RawVec(); \
auto& res = res_zv->RawVec(); \
for ( auto i = 0U; i < n; ++i ) \
if ( v[i] ) \
{ \
@ -479,7 +479,7 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
// well move the whole kit-and-caboodle into the Exec method). But
// that seems like a lot of code bloat for only a very modest gain.
auto& vec2 = *v2->RawVec();
auto& vec2 = v2->RawVec();
auto n = vec2.size();
auto vec1_ptr = new vector<std::optional<ZVal>>(n);
auto& vec1 = *vec1_ptr;
@ -511,8 +511,8 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
{
// See comment above re further speed-up.
auto& vec2 = *v2->RawVec();
auto& vec3 = *v3->RawVec();
auto& vec2 = v2->RawVec();
auto& vec3 = v3->RawVec();
auto n = vec2.size();
auto vec1_ptr = new vector<std::optional<ZVal>>(n);
auto& vec1 = *vec1_ptr;