mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
Use json::emplace to avoid some extra calls to operator[]
This commit is contained in:
parent
c8f2d52d91
commit
d4d1009b5c
4 changed files with 12 additions and 12 deletions
11
src/Val.cc
11
src/Val.cc
|
@ -494,8 +494,8 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new
|
|||
case TYPE_PORT:
|
||||
{
|
||||
auto* pval = val->AsPortVal();
|
||||
j["port"] = pval->Port();
|
||||
j["proto"] = pval->Protocol();
|
||||
j.emplace("port", pval->Port());
|
||||
j.emplace("proto", pval->Protocol());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -577,7 +577,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new
|
|||
else
|
||||
key_string = key_json.dump();
|
||||
|
||||
j[key_string] = BuildJSON(entry_value, only_loggable, re);
|
||||
j.emplace(key_string, BuildJSON(entry_value, only_loggable, re));
|
||||
}
|
||||
|
||||
Unref(lv);
|
||||
|
@ -614,7 +614,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new
|
|||
Val* value = key_field->Lookup("value", true);
|
||||
|
||||
if ( value && ( ! only_loggable || key_field->Lookup("log")->AsBool() ) )
|
||||
j[key_string] = BuildJSON(value, only_loggable, re);
|
||||
j.emplace(key_string, BuildJSON(value, only_loggable, re));
|
||||
}
|
||||
|
||||
delete fields;
|
||||
|
@ -646,9 +646,8 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new
|
|||
|
||||
case TYPE_OPAQUE:
|
||||
{
|
||||
j = ZeekJson::object();
|
||||
auto* oval = val->AsOpaqueVal();
|
||||
j["opaque_type"] = OpaqueMgr::mgr()->TypeID(oval);
|
||||
j = { { "opaque_type", OpaqueMgr::mgr()->TypeID(oval) } };
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
|||
if ( new_entry.is_null() )
|
||||
return false;
|
||||
|
||||
j[fields[i]->name] = new_entry;
|
||||
j.emplace(fields[i]->name, new_entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,11 +182,7 @@ ZeekJson JSON::BuildJSON(Value* val, const string& name) const
|
|||
}
|
||||
|
||||
if ( ! name.empty() && ! j.is_null() )
|
||||
{
|
||||
ZeekJson j2 = ZeekJson::object();
|
||||
j2[name] = j;
|
||||
return j2;
|
||||
}
|
||||
return { { name, j } };
|
||||
|
||||
return j;
|
||||
}
|
||||
|
|
|
@ -38,3 +38,4 @@ true
|
|||
{"10.1.1.1":{"a":1},"10.2.2.2":{"b":2}}
|
||||
{"10.1.1.1":[1,2],"10.2.2.2":[3,5]}
|
||||
{"1":{"s":"test"}}
|
||||
{"opaque_type":"TopkVal"}
|
||||
|
|
|
@ -122,4 +122,8 @@ event zeek_init()
|
|||
print to_json(ta3);
|
||||
print to_json(ta4);
|
||||
print to_json(ta5, T);
|
||||
|
||||
# Opaque
|
||||
local o1: opaque of topk = topk_init(5);
|
||||
print to_json(o1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue