<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[191874] trunk/Source/WTF</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/191874">191874</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2015-11-01 18:47:59 -0800 (Sun, 01 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>ASCIICType refinements
https://bugs.webkit.org/show_bug.cgi?id=150787
Reviewed by Geoffrey Garen.
Refined ASCIICType.h by using narrower types. The most valuable part of this
is the part where the result of toASCIIHexValue is uint8_t instead of int;
that's slightly better for RGB values that the compiler needs to know fit
into a byte (coming in some Color work I plan to do soon).
* wtf/ASCIICType.h: Used CharacterType instead of CharType throughout, and
also sorted the using declarations at the bottom of the header.
(WTF::isASCII): Use the name "character" instead of "c".
(WTF::isASCIIAlpha): Ditto. Also use isASCIILower and toASCIILowerUnchecked
instead of writing it out.
(WTF::isASCIIDigit): Ditto.
(WTF::isASCIIAlphanumeric): Ditto.
(WTF::isASCIIHexDigit): Ditto. Also use toASCIILowerUnchecked instead of
writing it out.
(WTF::isASCIILower): Ditto.
(WTF::isASCIIBinaryDigit): Ditto. Also removed unneeded parentheses to match
the style of the rest of the file.
(WTF::isASCIIOctalDigit): Ditto.
(WTF::isASCIIPrintable): Ditto.
(WTF::isASCIISpace): Ditto.
(WTF::isASCIIUpper): Ditto.
(WTF::toASCIILower): Ditto. Also use isASCIIUpper instead of writing it out.
(WTF::toASCIILowerUnchecked): Tweaked comment.
(WTF::toASCIIUpper): Ditto. Also use isASCIILower instead of writing it out.
(WTF::toASCIIHexValue): Ditto. Also change return type from int to uint8_t.
Also broke a single assertion with && into two separate assertions and got
rid of unnnecessary masking with 0xF0 after shifting left. Also renamed
arguments for the two argument value so they are more sensible.
(WTF::lowerNibbleToASCIIHexDigit): Changed argument type to uint8_t, since
this function does not take a character. Also called it "value" instead of "c".
Also slightly tweaked how the expression is written.
(WTF::upperNibbleToASCIIHexDigit): Ditto. Using the more specific type also
got rid of the need to explicitly mask in this function.
(WTF::isASCIIAlphaCaselessEqual): Renamed the arguments for greater clarity.
With the new clearer argument names, the comment was superfluous.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfASCIICTypeh">trunk/Source/WTF/wtf/ASCIICType.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (191873 => 191874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2015-11-02 02:31:02 UTC (rev 191873)
+++ trunk/Source/WTF/ChangeLog        2015-11-02 02:47:59 UTC (rev 191874)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2015-11-01 Darin Adler <darin@apple.com>
+
+ ASCIICType refinements
+ https://bugs.webkit.org/show_bug.cgi?id=150787
+
+ Reviewed by Geoffrey Garen.
+
+ Refined ASCIICType.h by using narrower types. The most valuable part of this
+ is the part where the result of toASCIIHexValue is uint8_t instead of int;
+ that's slightly better for RGB values that the compiler needs to know fit
+ into a byte (coming in some Color work I plan to do soon).
+
+ * wtf/ASCIICType.h: Used CharacterType instead of CharType throughout, and
+ also sorted the using declarations at the bottom of the header.
+ (WTF::isASCII): Use the name "character" instead of "c".
+ (WTF::isASCIIAlpha): Ditto. Also use isASCIILower and toASCIILowerUnchecked
+ instead of writing it out.
+ (WTF::isASCIIDigit): Ditto.
+ (WTF::isASCIIAlphanumeric): Ditto.
+ (WTF::isASCIIHexDigit): Ditto. Also use toASCIILowerUnchecked instead of
+ writing it out.
+ (WTF::isASCIILower): Ditto.
+ (WTF::isASCIIBinaryDigit): Ditto. Also removed unneeded parentheses to match
+ the style of the rest of the file.
+ (WTF::isASCIIOctalDigit): Ditto.
+ (WTF::isASCIIPrintable): Ditto.
+ (WTF::isASCIISpace): Ditto.
+ (WTF::isASCIIUpper): Ditto.
+ (WTF::toASCIILower): Ditto. Also use isASCIIUpper instead of writing it out.
+ (WTF::toASCIILowerUnchecked): Tweaked comment.
+ (WTF::toASCIIUpper): Ditto. Also use isASCIILower instead of writing it out.
+ (WTF::toASCIIHexValue): Ditto. Also change return type from int to uint8_t.
+ Also broke a single assertion with && into two separate assertions and got
+ rid of unnnecessary masking with 0xF0 after shifting left. Also renamed
+ arguments for the two argument value so they are more sensible.
+ (WTF::lowerNibbleToASCIIHexDigit): Changed argument type to uint8_t, since
+ this function does not take a character. Also called it "value" instead of "c".
+ Also slightly tweaked how the expression is written.
+ (WTF::upperNibbleToASCIIHexDigit): Ditto. Using the more specific type also
+ got rid of the need to explicitly mask in this function.
+ (WTF::isASCIIAlphaCaselessEqual): Renamed the arguments for greater clarity.
+ With the new clearer argument names, the comment was superfluous.
+
</ins><span class="cx"> 2015-11-01 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> Dominators should be factored out of the DFG
</span></span></pre></div>
<a id="trunkSourceWTFwtfASCIICTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/ASCIICType.h (191873 => 191874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/ASCIICType.h        2015-11-02 02:31:02 UTC (rev 191873)
+++ trunk/Source/WTF/wtf/ASCIICType.h        2015-11-02 02:47:59 UTC (rev 191874)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2007-2009, 2011, 2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -63,157 +63,155 @@
</span><span class="cx"> 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
</span><span class="cx"> };
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCII(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCII(CharacterType character)
</ins><span class="cx"> {
</span><del>- return !(c & ~0x7F);
</del><ins>+ return !(character & ~0x7F);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIAlpha(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIILower(CharacterType character)
</ins><span class="cx"> {
</span><del>- return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
</del><ins>+ return character >= 'a' && character <= 'z';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIDigit(CharType c)
</del><ins>+template<typename CharacterType> inline CharacterType toASCIILowerUnchecked(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c >= '0' && c <= '9';
</del><ins>+ // This function can be used for comparing any input character
+ // to a lowercase English character. The isASCIIAlphaCaselessEqual
+ // below should be used for regular comparison of ASCII alpha
+ // characters, but switch statements in CSS tokenizer instead make
+ // direct use of this function.
+ return character | 0x20;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIAlphanumeric(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIAlpha(CharacterType character)
</ins><span class="cx"> {
</span><del>- return isASCIIDigit(c) || isASCIIAlpha(c);
</del><ins>+ return isASCIILower(toASCIILowerUnchecked(character));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIHexDigit(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIDigit(CharacterType character)
</ins><span class="cx"> {
</span><del>- return isASCIIDigit(c) || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
</del><ins>+ return character >= '0' && character <= '9';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIILower(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIAlphanumeric(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c >= 'a' && c <= 'z';
</del><ins>+ return isASCIIDigit(character) || isASCIIAlpha(character);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIBinaryDigit(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIHexDigit(CharacterType character)
</ins><span class="cx"> {
</span><del>- return (c == '0') || (c == '1');
</del><ins>+ return isASCIIDigit(character) || (toASCIILowerUnchecked(character) >= 'a' && toASCIILowerUnchecked(character) <= 'f');
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIOctalDigit(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIBinaryDigit(CharacterType character)
</ins><span class="cx"> {
</span><del>- return (c >= '0') && (c <= '7');
</del><ins>+ return character == '0' || character == '1';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIPrintable(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIOctalDigit(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c >= ' ' && c <= '~';
</del><ins>+ return character >= '0' && character <= '7';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-/*
- Statistics from a run of Apple's page load test for callers of isASCIISpace:
-
- character count
- --------- -----
- non-spaces 689383
- 20 space 294720
- 0A \n 89059
- 09 \t 28320
- 0D \r 0
- 0C \f 0
- 0B \v 0
- */
-template<typename CharType> inline bool isASCIISpace(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIPrintable(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
</del><ins>+ return character >= ' ' && character <= '~';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIUpper(CharType c)
</del><ins>+/*
+ Statistics from a run of Apple's page load test for callers of isASCIISpace:
+
+ character count
+ --------- -----
+ non-spaces 689383
+ 20 space 294720
+ 0A \n 89059
+ 09 \t 28320
+ 0D \r 0
+ 0C \f 0
+ 0B \v 0
+
+ Because of those, we first check to quickly return false for non-control characters,
+ then check for space itself to quickly return true for that case, then do the rest.
+*/
+template<typename CharacterType> inline bool isASCIISpace(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c >= 'A' && c <= 'Z';
</del><ins>+ return character <= ' ' && (character == ' ' || (character <= 0xD && character >= 0x9));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline CharType toASCIILower(CharType c)
</del><ins>+template<typename CharacterType> inline bool isASCIIUpper(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c | ((c >= 'A' && c <= 'Z') << 5);
</del><ins>+ return character >= 'A' && character <= 'Z';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<>
-inline char toASCIILower(char c)
</del><ins>+template<typename CharacterType> inline CharacterType toASCIILower(CharacterType character)
</ins><span class="cx"> {
</span><del>- return static_cast<char>(asciiCaseFoldTable[static_cast<unsigned char>(c)]);
</del><ins>+ return character | (isASCIIUpper(character) << 5);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<>
-inline LChar toASCIILower(LChar c)
</del><ins>+template<> inline char toASCIILower(char character)
</ins><span class="cx"> {
</span><del>- return asciiCaseFoldTable[c];
</del><ins>+ return static_cast<char>(asciiCaseFoldTable[static_cast<uint8_t>(character)]);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline CharType toASCIILowerUnchecked(CharType character)
</del><ins>+template<> inline LChar toASCIILower(LChar character)
</ins><span class="cx"> {
</span><del>- // This function can be used for comparing any input character
- // to a lowercase English character. The isASCIIAlphaCaselessEqual
- // below should be used for regular comparison of ASCII alpha
- // characters, but switch statements in CSS tokenizer require
- // direct use of this function.
- return character | 0x20;
</del><ins>+ return asciiCaseFoldTable[character];
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline CharType toASCIIUpper(CharType c)
</del><ins>+template<typename CharacterType> inline CharacterType toASCIIUpper(CharacterType character)
</ins><span class="cx"> {
</span><del>- return c & ~((c >= 'a' && c <= 'z') << 5);
</del><ins>+ return character & ~(isASCIILower(character) << 5);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline int toASCIIHexValue(CharType c)
</del><ins>+template<typename CharacterType> inline uint8_t toASCIIHexValue(CharacterType character)
</ins><span class="cx"> {
</span><del>- ASSERT(isASCIIHexDigit(c));
- return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
</del><ins>+ ASSERT(isASCIIHexDigit(character));
+ return character < 'A' ? character - '0' : (character - 'A' + 10) & 0xF;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline int toASCIIHexValue(CharType upperValue, CharType lowerValue)
</del><ins>+template<typename CharacterType> inline uint8_t toASCIIHexValue(CharacterType firstCharacter, CharacterType secondCharacter)
</ins><span class="cx"> {
</span><del>- ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue));
- return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerValue);
</del><ins>+ return toASCIIHexValue(firstCharacter) << 4 | toASCIIHexValue(secondCharacter);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-inline char lowerNibbleToASCIIHexDigit(char c)
</del><ins>+inline char lowerNibbleToASCIIHexDigit(uint8_t value)
</ins><span class="cx"> {
</span><del>- char nibble = c & 0xF;
- return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
</del><ins>+ uint8_t nibble = value & 0xF;
+ return nibble + (nibble < 10 ? '0' : 'A' - 10);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-inline char upperNibbleToASCIIHexDigit(char c)
</del><ins>+inline char upperNibbleToASCIIHexDigit(uint8_t value)
</ins><span class="cx"> {
</span><del>- char nibble = (c >> 4) & 0xF;
- return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
</del><ins>+ uint8_t nibble = value >> 4;
+ return nibble + (nibble < 10 ? '0' : 'A' - 10);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-template<typename CharType> inline bool isASCIIAlphaCaselessEqual(CharType cssCharacter, char character)
</del><ins>+template<typename CharacterType> inline bool isASCIIAlphaCaselessEqual(CharacterType inputCharacter, char expectedASCIILowercaseLetter)
</ins><span class="cx"> {
</span><del>- // This function compares a (preferrably) constant ASCII
- // lowercase letter to any input character.
- ASSERT(character >= 'a' && character <= 'z');
- return LIKELY(toASCIILowerUnchecked(cssCharacter) == character);
</del><ins>+ ASSERT(isASCIILower(expectedASCIILowercaseLetter));
+ return LIKELY(toASCIILowerUnchecked(inputCharacter) == expectedASCIILowercaseLetter);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> using WTF::isASCII;
</span><span class="cx"> using WTF::isASCIIAlpha;
</span><ins>+using WTF::isASCIIAlphaCaselessEqual;
</ins><span class="cx"> using WTF::isASCIIAlphanumeric;
</span><ins>+using WTF::isASCIIBinaryDigit;
</ins><span class="cx"> using WTF::isASCIIDigit;
</span><span class="cx"> using WTF::isASCIIHexDigit;
</span><span class="cx"> using WTF::isASCIILower;
</span><del>-using WTF::isASCIIBinaryDigit;
</del><span class="cx"> using WTF::isASCIIOctalDigit;
</span><span class="cx"> using WTF::isASCIIPrintable;
</span><span class="cx"> using WTF::isASCIISpace;
</span><span class="cx"> using WTF::isASCIIUpper;
</span><ins>+using WTF::lowerNibbleToASCIIHexDigit;
</ins><span class="cx"> using WTF::toASCIIHexValue;
</span><span class="cx"> using WTF::toASCIILower;
</span><span class="cx"> using WTF::toASCIILowerUnchecked;
</span><span class="cx"> using WTF::toASCIIUpper;
</span><del>-using WTF::lowerNibbleToASCIIHexDigit;
</del><span class="cx"> using WTF::upperNibbleToASCIIHexDigit;
</span><del>-using WTF::isASCIIAlphaCaselessEqual;
</del><span class="cx">
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>
</body>
</html>