Commit 8896ceb6 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Micro-optimise mask_prefix.

parent 4579b298
......@@ -207,8 +207,8 @@ do_debugf(int level, const char *format, ...)
}
int
in_prefix(const unsigned char *address,
const unsigned char *prefix, unsigned char plen)
in_prefix(const unsigned char *restrict address,
const unsigned char *restrict prefix, unsigned char plen)
{
unsigned char m;
......@@ -218,14 +218,17 @@ in_prefix(const unsigned char *address,
if(memcmp(address, prefix, plen / 8) != 0)
return 0;
if(plen % 8 == 0)
return 1;
m = 0xFF << (8 - (plen % 8));
return ((address[plen / 8] & m) == (prefix[plen / 8] & m));
}
unsigned char *
mask_prefix(unsigned char *ret,
const unsigned char *prefix, unsigned char plen)
mask_prefix(unsigned char *restrict ret,
const unsigned char *restrict prefix, unsigned char plen)
{
if(plen >= 128) {
memcpy(ret, prefix, 16);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment