mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
binpac: Arrays now suport the &transient attribute.
If set, parsed elements won't actually be added to the array, and read access to the array aren't permitted. This is helpful to save memory in the case of large arrays for which elements don't need (or can't) be buffered.
This commit is contained in:
parent
5db7ba4050
commit
092d049f8e
1 changed files with 79 additions and 66 deletions
|
@ -92,6 +92,9 @@ Type *ArrayType::ElementDataType() const
|
|||
|
||||
string ArrayType::EvalElement(const string &array, const string &index) const
|
||||
{
|
||||
if ( attr_transient_ )
|
||||
throw Exception(this, "cannot access element in &transient array");
|
||||
|
||||
return strfmt("(*(%s))[%s]", array.c_str(), index.c_str());
|
||||
}
|
||||
|
||||
|
@ -313,6 +316,9 @@ void ArrayType::GenPubDecls(Output *out_h, Env *env)
|
|||
|
||||
if ( declared_as_type() )
|
||||
{
|
||||
if ( attr_transient_ )
|
||||
throw Exception(this, "cannot access element in &transient array");
|
||||
|
||||
out_h->println("int size() const { return %s ? %s->size() : 0; }",
|
||||
env->RValue(value_var()),
|
||||
env->RValue(value_var()));
|
||||
|
@ -418,6 +424,13 @@ string ArrayType::GenArrayInit(Output *out_cc, Env *env, bool known_array_length
|
|||
void ArrayType::GenElementAssignment(Output *out_cc, Env *env,
|
||||
string const &array_str, bool use_vector)
|
||||
{
|
||||
if ( attr_transient_ )
|
||||
{
|
||||
// Just discard.
|
||||
out_cc->println("delete %s;", env->LValue(elem_var()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Assign the element
|
||||
if ( ! use_vector )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue