]> git.ipfire.org Git - thirdparty/bind9.git/commit
Refactor the common buffer manipulation in rdataslab.c in macros
authorOndřej Surý <ondrej@isc.org>
Thu, 29 Feb 2024 21:26:29 +0000 (22:26 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 24 May 2024 07:52:45 +0000 (09:52 +0200)
commit03ed19cf7163d658c2457ecebf9252ffc92750c9
treeaaecaf1bb2c77858397aa5b67904baa055afbf40
parentc8289279f07f9b1e7862e0cbd0cd5cdcd565d581
Refactor the common buffer manipulation in rdataslab.c in macros

The rdataslab.c was full of code like this:

        length = raw[0] * 256 + raw[1];

and

        count2 = *current2++ * 256;
        count2 += *current2++;

Refactor code like this into peek_uint16() and get_uint16 macros
to prevent code repetition and possible mistakes when copy and
pasting the same code over and over.

As a side note for an entertainment of a careful reader of the commit
messages: The byte manipulation was changed from multiplication and
addition to shift with or.

The difference in the assembly looks like this:

MUL and ADD:

movzx   eax, BYTE PTR [rdi]
        movzx   edi, BYTE PTR [rdi+1]
        sal     eax, 8
        or      edi, eax

SHIFT and OR:

        movzx   edi, WORD PTR [rdi]
        rol     di, 8
        movzx   edi, di

If the result and/or buffer is then being used after the macro call,
there's more differences in favor of the SHIFT+OR solution.
lib/dns/rdataslab.c