Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rec: Compute size *estimate* for record cache allocated size #15038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pdns/dnsname.hh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public:
return d_storage;
}

[[nodiscard]] size_t sizeEstimate() const
{
return d_storage.size(); // knowingly overestimating small strings as most string
// implementations have internal capacity and we always include
// sizeof(*this)
}

bool has8bitBytes() const; /* returns true if at least one byte of the labels forming the name is not included in [A-Za-z0-9_*./@ \\:-] */

class RawLabelsVisitor
Expand Down
12 changes: 12 additions & 0 deletions pdns/dnsparser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ public:
d_locked.store(true);
}

[[nodiscard]] virtual size_t sizeEstimate() const = 0;

protected:
typedef std::map<std::pair<uint16_t, uint16_t>, makerfunc_t* > typemap_t;
typedef std::map<std::pair<uint16_t, uint16_t>, zmakerfunc_t* > zmakermap_t;
Expand Down Expand Up @@ -433,6 +435,11 @@ public:

return *d_content == *rhs.d_content;
}

[[nodiscard]] size_t sizeEstimate() const
{
return sizeof(*this) + d_name.sizeEstimate() + (d_content ? d_content->sizeEstimate() : 0U);
}
};

struct DNSZoneRecord
Expand Down Expand Up @@ -469,6 +476,11 @@ public:
return d_record;
}

[[nodiscard]] size_t sizeEstimate() const override
{
return sizeof(*this) + d_dr.sizeEstimate() + d_record.size();
}

private:
DNSRecord d_dr;
vector<uint8_t> d_record;
Expand Down
Loading
Loading