[Webkit-unassigned] [Bug 35233] Optimize Latin-1 decoding in TextCodecLatin1::decode()

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Feb 22 10:00:56 PST 2010


https://bugs.webkit.org/show_bug.cgi?id=35233


Darin Adler <darin at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #49217|review?, commit-queue?      |review-
               Flag|                            |




--- Comment #4 from Darin Adler <darin at apple.com>  2010-02-22 10:00:56 PST ---
(From update of attachment 49217)
We capitalize acronyms in WebKit code, so the constant should be called
nonASCIIMask rather than nonAsciiMask.

> +#if CPU(X86_64) || CPU(SPARC64) || CPU(IA64) || CPU(PPC64)
> +const uintptr_t nonAsciiMask = 0x8080808080808080;
> +#else
> +const uintptr_t nonAsciiMask = 0x80808080;
> +#endif

This can be done without ifdefs as is done in the WTF header file
HashFunctions.h.

    template<size_t size> struct NonASCIIMask;
    template<> struct NonASCIIMask<4> { static unsigned value() { return
0x80808080U; } }
    template<> struct NonASCIIMask<8> { static unsigned long long value() {
return 0x8080808080808080UL; }

Then say:

    if (chunk & NonASCIIMask<sizeof(uintptr_t)>::value())

While this is a bit harder to read, it's safer. The code in the patch as is
would fail in a subtle way if you had a 64-bit platform not listed in the
ifdefs, only checking half of the bits.

The copying can be done the same way:

> +                    dest[0] = src[0];
> +                    dest[1] = src[1];
> +                    dest[2] = src[2];
> +                    dest[3] = src[3];
> +#if CPU(X86_64) || CPU(SPARC64) || CPU(IA64) || CPU(PPC64)
> +                    dest[4] = src[4];
> +                    dest[5] = src[5];
> +                    dest[6] = src[6];
> +                    dest[7] = src[7];
> +#endif

This copying can also be done with the template technique above, with an inline
template member function that copies the correct number of bytes.

Possibly better for platforms that allow unaligned access, this can be done
with a single line:

    *reinterpret_cast<uintptr_t*>(dest) = chunk;

You can see in StringHash.h that many platforms do allow unaligned access. I
predict it would be a speedup to use that when possible.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list