mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
refine Val "footprint" to equate long strings with multiple objects
This commit is contained in:
parent
d7e30d9ee2
commit
1f9fa4304d
6 changed files with 20 additions and 1 deletions
6
NEWS
6
NEWS
|
@ -58,6 +58,12 @@ Changed Functionality
|
||||||
``frameworks/signatures/iso-9660`` which also increases the BOF buffer sufficiently.
|
``frameworks/signatures/iso-9660`` which also increases the BOF buffer sufficiently.
|
||||||
Note, doing so may increase memory and CPU usage significantly.
|
Note, doing so may increase memory and CPU usage significantly.
|
||||||
|
|
||||||
|
- The ``val_footprint()`` BiF now factors in the size of strings when reporting
|
||||||
|
footprints, roughly equating a string's size with the number of elements
|
||||||
|
comparable to that length. As before, footprints are not meant to be precise
|
||||||
|
but mainly for providing comparisons, which is why this is not a breaking
|
||||||
|
change.
|
||||||
|
|
||||||
Removed Functionality
|
Removed Functionality
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
2
doc
2
doc
|
@ -1 +1 @@
|
||||||
Subproject commit 9f9ebde62380a3012a1471d9ff1c1c91c7aa69da
|
Subproject commit 5a9c406b74d75373b22531cf296e3fb14646a9b3
|
|
@ -855,6 +855,10 @@ StringValPtr StringVal::Replace(RE_Matcher* re, const String& repl, bool do_all)
|
||||||
return make_intrusive<StringVal>(new String(true, result, r - result));
|
return make_intrusive<StringVal>(new String(true, result, r - result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int StringVal::ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const {
|
||||||
|
return 1 /* this object */ + static_cast<unsigned int>(Len()) / sizeof(Val);
|
||||||
|
}
|
||||||
|
|
||||||
static std::variant<ValPtr, std::string> BuildVal(const rapidjson::Value& j, const TypePtr& t,
|
static std::variant<ValPtr, std::string> BuildVal(const rapidjson::Value& j, const TypePtr& t,
|
||||||
const FuncPtr& key_func) {
|
const FuncPtr& key_func) {
|
||||||
auto mismatch_err = [t, &j]() {
|
auto mismatch_err = [t, &j]() {
|
||||||
|
|
|
@ -564,6 +564,8 @@ public:
|
||||||
StringValPtr Replace(RE_Matcher* re, const String& repl, bool do_all);
|
StringValPtr Replace(RE_Matcher* re, const String& repl, bool do_all);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
|
||||||
|
|
||||||
void ValDescribe(ODesc* d) const override;
|
void ValDescribe(ODesc* d) const override;
|
||||||
ValPtr DoClone(CloneState* state) override;
|
ValPtr DoClone(CloneState* state) override;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ l1, 3
|
||||||
l1b, 6
|
l1b, 6
|
||||||
l2, 7
|
l2, 7
|
||||||
l2b, 9
|
l2b, 9
|
||||||
|
l2c, T
|
||||||
v1, 8
|
v1, 8
|
||||||
v2, 18
|
v2, 18
|
||||||
v3, 11
|
v3, 11
|
||||||
|
|
|
@ -54,6 +54,12 @@ event zeek_init()
|
||||||
local l2b = r2($a=3, $b1=99.0, $c="I'm here");
|
local l2b = r2($a=3, $b1=99.0, $c="I'm here");
|
||||||
print "l2b", val_footprint(l2b);
|
print "l2b", val_footprint(l2b);
|
||||||
|
|
||||||
|
local l2c = r2($a=3, $b1=99e99, $c="I'm here and really very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long-winded");
|
||||||
|
# In the following, we just print the comparison rather than the
|
||||||
|
# actual footprint value, since the latter will change depending
|
||||||
|
# on the size of C++ pointers and the like.
|
||||||
|
print "l2c", val_footprint(l2c) > val_footprint(l2b);
|
||||||
|
|
||||||
local v1 = vector(9, 7, 3, 1);
|
local v1 = vector(9, 7, 3, 1);
|
||||||
print "v1", val_footprint(v1);
|
print "v1", val_footprint(v1);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue