Bug 73799 - Update String::containsOnlyASCII() to handle 8 bits strings
Summary: Update String::containsOnlyASCII() to handle 8 bits strings
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-04 22:34 PST by Benjamin Poulain
Modified: 2011-12-05 15:58 PST (History)
3 users (show)

See Also:


Attachments
Patch (5.80 KB, patch)
2011-12-04 22:46 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (6.56 KB, patch)
2011-12-05 15:18 PST, Benjamin Poulain
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2011-12-04 22:34:40 PST
Update String::containsOnlyASCII() to handle 8 bits strings
Comment 1 Benjamin Poulain 2011-12-04 22:46:08 PST
Created attachment 117845 [details]
Patch
Comment 2 Sam Weinig 2011-12-05 10:40:03 PST
Comment on attachment 117845 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=117845&action=review

> Source/JavaScriptCore/wtf/text/WTFString.h:504
> +    if (is8Bit()) {
> +        const LChar* characters = characters8();
> +        LChar ored = 0;
> +        for (size_t i = 0; i < m_impl->length(); ++i)
> +            ored |= characters[i];
> +        return !(ored & 0x80);
> +    }

It would probably make sense to add a charactersAreAllASCII that takes LChars, to match the one that takes UChars, and call it here.
Comment 3 Benjamin Poulain 2011-12-05 15:18:59 PST
Created attachment 117946 [details]
Patch
Comment 4 Darin Adler 2011-12-05 15:22:14 PST
Comment on attachment 117946 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=117946&action=review

> Source/JavaScriptCore/wtf/text/WTFString.h:492
>      return !(ored & 0xFF80);

This is the only thing  here that is specific to 2 bytes. It could be written like this:

    return !(ored & ~0x7F);

And then it would only require that CharType was the size of an integer or smaller. Or it could be written like this:

    CharType lowBits = 0x7F;
    return !(ored & ~lowBits);

And then it would work with pretty much any type and a COMPILE_ASSERT would not be needed.
Comment 5 Benjamin Poulain 2011-12-05 15:25:10 PST
I like that. Thanks for the review.
Comment 6 Benjamin Poulain 2011-12-05 15:58:14 PST
Committed r102059: <http://trac.webkit.org/changeset/102059>