Merge remote-tracking branch 'origin/topic/vern/val-footprint-strings'

* origin/topic/vern/val-footprint-strings:
  refine Val "footprint" to equate long strings with multiple objects
This commit is contained in:
Tim Wojtulewicz 2024-05-02 19:00:53 -07:00
commit cdcd83c8cc
8 changed files with 25 additions and 2 deletions

View file

@ -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));
}
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,
const FuncPtr& key_func) {
auto mismatch_err = [t, &j]() {

View file

@ -564,6 +564,8 @@ public:
StringValPtr Replace(RE_Matcher* re, const String& repl, bool do_all);
protected:
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
void ValDescribe(ODesc* d) const override;
ValPtr DoClone(CloneState* state) override;