On Fri, Mar 6, 2015 at 1:37 PM, Xueming Shen <xueming.s...@oracle.com> wrote:
> On 03/06/2015 12:46 PM, Martin Buchholz wrote: > >> Hi jar/zip maintainers, >> >> Here's an easy improvement. >> >> http://cr.openjdk.java.net/~martin/webrevs/openjdk9/PKsig/ < >> http://cr.openjdk.java.net/%7Emartin/webrevs/openjdk9/PKsig/> >> https://bugs.openjdk.java.net/browse/JDK-8074579 >> > Looks fine, assume the statement of "byte-byte-byte comparing is more > efficient" is true > In most cases, the signature comparing is just a "confirm", should not > miss though. > Reading the whole signature with one read might be more efficient if unaligned 4-byte reads were available and being used (which they're not). IIRC we experimented with that on x86 but found no improvement (perhaps because many fields are 2-byte). Anyways, it should still be a win because the individual bytes aren't being assembled/shifted into an int, and the byte comparisons can use "immediate" instructions. (a reason to worry just occurred to me - my change introduces more branches, which might be slower when lacking branch prediction... hmmmm ...) Ahhh, of course, we can remove the branches by doing: #define PKZIP_SIGNATURE_AT(p, b2, b3) \ ((((p)[0] - 'P') | ((p)[1] - 'K') | ((p)[2] - b2) | ((p)[3] - b3)) == 0) Well, now that looks like much less of a win, performance wise... but still worth doing. We haz new webrev.