Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: net/dns/dns_response.cc

Issue 2790823003: net: calculate dns header size only once per query/response (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/dns_query.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_response.cc
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc
index f168a255f39db80490350457131c1a393024f56a..5d234244a09ed7448bf89ec874d881f1b1e69c1f 100644
--- a/net/dns/dns_response.cc
+++ b/net/dns/dns_response.cc
@@ -21,6 +21,8 @@ namespace net {
namespace {
+const size_t kHeaderSize = sizeof(dns_protocol::Header);
+
const uint8_t kRcodeMask = 0xf;
} // namespace
@@ -185,30 +187,25 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) {
return false;
// Match the question section.
- const size_t hdr_size = sizeof(dns_protocol::Header);
const base::StringPiece question = query.question();
- if (question != base::StringPiece(io_buffer_->data() + hdr_size,
- question.size())) {
+ if (question !=
+ base::StringPiece(io_buffer_->data() + kHeaderSize, question.size())) {
return false;
}
// Construct the parser.
- parser_ = DnsRecordParser(io_buffer_->data(),
- nbytes,
- hdr_size + question.size());
+ parser_ = DnsRecordParser(io_buffer_->data(), nbytes,
+ kHeaderSize + question.size());
return true;
}
bool DnsResponse::InitParseWithoutQuery(int nbytes) {
DCHECK_GE(nbytes, 0);
- size_t hdr_size = sizeof(dns_protocol::Header);
-
- if (nbytes < static_cast<int>(hdr_size) || nbytes >= io_buffer_->size())
+ if (nbytes < static_cast<int>(kHeaderSize) || nbytes >= io_buffer_->size())
return false;
- parser_ = DnsRecordParser(
- io_buffer_->data(), nbytes, hdr_size);
+ parser_ = DnsRecordParser(io_buffer_->data(), nbytes, kHeaderSize);
unsigned qdcount = base::NetToHost16(header()->qdcount);
for (unsigned i = 0; i < qdcount; ++i) {
@@ -250,10 +247,9 @@ base::StringPiece DnsResponse::qname() const {
// The response is HEADER QNAME QTYPE QCLASS ANSWER.
// |parser_| is positioned at the beginning of ANSWER, so the end of QNAME is
// two uint16_ts before it.
- const size_t hdr_size = sizeof(dns_protocol::Header);
const size_t qname_size =
- parser_.GetOffset() - 2 * sizeof(uint16_t) - hdr_size;
- return base::StringPiece(io_buffer_->data() + hdr_size, qname_size);
+ parser_.GetOffset() - 2 * sizeof(uint16_t) - kHeaderSize;
+ return base::StringPiece(io_buffer_->data() + kHeaderSize, qname_size);
}
uint16_t DnsResponse::qtype() const {
« no previous file with comments | « net/dns/dns_query.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698