This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients eric.snow, lemburg, pitrou, serhiy.storchaka, vstinner
Date 2013-04-13.15:30:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1365867012.14.0.972439921641.issue17628@psf.upfronthosting.co.za>
In-reply-to
Content
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)
    }
History
Date User Action Args
2013-04-13 15:30:12serhiy.storchakasetrecipients: + serhiy.storchaka, lemburg, pitrou, vstinner, eric.snow
2013-04-13 15:30:12serhiy.storchakasetmessageid: <1365867012.14.0.972439921641.issue17628@psf.upfronthosting.co.za>
2013-04-13 15:30:12serhiy.storchakalinkissue17628 messages
2013-04-13 15:30:11serhiy.storchakacreate