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.
Edited by Ondřej Surý