Serhiy Storchaka added the comment:
Some crazy ideas.
Try something like this:
#define BLOCK unsigned long
if (size >= sizeof(BLOCK)) {
if (*(BLOCK*)data1 != *(BLOCK*)data2)
return 0;
return (memcmp((unsigned char*)data1 + sizeof(BLOCK),
(unsigned char*)data2 + sizeof(BLOCK), size) == 0);
}
if (*(unsigned char*)data1 != *(unsigned char*)data2)
return 0;
return (memcmp(data1, data2, size) == 0);
Or may be unroll memcmp for small size:
switch (size) {
#if SIZEOF_LONG == 8
case 7:
...
#endif
case 3:
...
case 2:
if (((unsigned char*)data1)[1] != ((unsigned char*)data2)[1])
return 0;
case 1:
if (((unsigned char*)data1)[0] != ((unsigned char*)data2)[0])
return 0;
case 0:
return 1;
default:
// case for size >= sizeof(BLOCK)
}
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17628>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com