Title: [165792] trunk/Source/WTF
Revision
165792
Author
[email protected]
Date
2014-03-17 20:00:06 -0700 (Mon, 17 Mar 2014)

Log Message

Remove most uses of deprecatedCharacter in WTF
https://bugs.webkit.org/show_bug.cgi?id=130317

Reviewed by Andreas Kling.

Re-landing after fixing the "80 instead of 0x80" typo in equalLatin1WithUTF8.

* wtf/text/AtomicString.cpp:
(WTF::HashAndUTF8CharactersTranslator::equal): Add an 8-bit code path to the
non-ASCII path.
(WTF::SubstringTranslator8::hash): Added.
(WTF::SubstringTranslator8::equal): Added.
(WTF::SubstringTranslator16::hash): Renamed class.
(WTF::SubstringTranslator16::equal): Ditto.
(WTF::AtomicString::add): Added an 8-bit code path to the substring case.

* wtf/text/Base64.cpp:
(WTF::base64Decode): Added an 8 bit code path.
(WTF::base64URLDecode): Ditto.

* wtf/text/StringImpl.cpp:
(WTF::StringImpl::find): Fixed a case that was incorrectly using characters16
without first using is8Bit. Need to return later to remove use of deprecatedCharacters.

* wtf/unicode/UTF8.cpp:
(WTF::Unicode::equalUTF16WithUTF8): Added a case for when the UTF-16 characters
are ASCII. Also removed the aEnd argument, since the caller only calls this when the
lengths are equal.
(WTF::Unicode::equalLatin1WithUTF8): Added.
* wtf/unicode/UTF8.h: Updated as described above.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (165791 => 165792)


--- trunk/Source/WTF/ChangeLog	2014-03-18 02:45:24 UTC (rev 165791)
+++ trunk/Source/WTF/ChangeLog	2014-03-18 03:00:06 UTC (rev 165792)
@@ -1,3 +1,36 @@
+2014-03-17  Darin Adler  <[email protected]>
+
+        Remove most uses of deprecatedCharacter in WTF
+        https://bugs.webkit.org/show_bug.cgi?id=130317
+
+        Reviewed by Andreas Kling.
+
+        Re-landing after fixing the "80 instead of 0x80" typo in equalLatin1WithUTF8.
+
+        * wtf/text/AtomicString.cpp:
+        (WTF::HashAndUTF8CharactersTranslator::equal): Add an 8-bit code path to the
+        non-ASCII path.
+        (WTF::SubstringTranslator8::hash): Added.
+        (WTF::SubstringTranslator8::equal): Added.
+        (WTF::SubstringTranslator16::hash): Renamed class.
+        (WTF::SubstringTranslator16::equal): Ditto.
+        (WTF::AtomicString::add): Added an 8-bit code path to the substring case.
+
+        * wtf/text/Base64.cpp:
+        (WTF::base64Decode): Added an 8 bit code path.
+        (WTF::base64URLDecode): Ditto.
+
+        * wtf/text/StringImpl.cpp:
+        (WTF::StringImpl::find): Fixed a case that was incorrectly using characters16
+        without first using is8Bit. Need to return later to remove use of deprecatedCharacters.
+
+        * wtf/unicode/UTF8.cpp:
+        (WTF::Unicode::equalUTF16WithUTF8): Added a case for when the UTF-16 characters
+        are ASCII. Also removed the aEnd argument, since the caller only calls this when the
+        lengths are equal.
+        (WTF::Unicode::equalLatin1WithUTF8): Added.
+        * wtf/unicode/UTF8.h: Updated as described above.
+
 2014-03-17  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r165721.

Modified: trunk/Source/WTF/wtf/text/AtomicString.cpp (165791 => 165792)


--- trunk/Source/WTF/wtf/text/AtomicString.cpp	2014-03-18 02:45:24 UTC (rev 165791)
+++ trunk/Source/WTF/wtf/text/AtomicString.cpp	2014-03-18 03:00:06 UTC (rev 165792)
@@ -187,9 +187,10 @@
 
         // If buffer contains only ASCII characters UTF-8 and UTF16 length are the same.
         if (buffer.utf16Length != buffer.length) {
-            const UChar* stringCharacters = string->deprecatedCharacters();
+            if (string->is8Bit())
+                return equalLatin1WithUTF8(string->characters8(), buffer.characters, buffer.characters + buffer.length);
 
-            return equalUTF16WithUTF8(stringCharacters, stringCharacters + string->length(), buffer.characters, buffer.characters + buffer.length);
+            return equalUTF16WithUTF8(string->characters16(), buffer.characters, buffer.characters + buffer.length);
         }
 
         if (string->is8Bit()) {
@@ -281,28 +282,42 @@
 };
 
 struct SubstringTranslator {
+    static void translate(StringImpl*& location, const SubstringLocation& buffer, unsigned hash)
+    {
+        location = &StringImpl::createSubstringSharingImpl(buffer.baseString, buffer.start, buffer.length).leakRef();
+        location->setHash(hash);
+        location->setIsAtomic(true);
+    }
+};
+
+struct SubstringTranslator8 : SubstringTranslator {
     static unsigned hash(const SubstringLocation& buffer)
     {
-        return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->deprecatedCharacters() + buffer.start, buffer.length);
+        return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters8() + buffer.start, buffer.length);
     }
 
     static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
     {
-        return WTF::equal(string, buffer.baseString->deprecatedCharacters() + buffer.start, buffer.length);
+        return WTF::equal(string, buffer.baseString->characters8() + buffer.start, buffer.length);
     }
+};
 
-    static void translate(StringImpl*& location, const SubstringLocation& buffer, unsigned hash)
+struct SubstringTranslator16 : SubstringTranslator {
+    static unsigned hash(const SubstringLocation& buffer)
     {
-        location = &StringImpl::createSubstringSharingImpl(buffer.baseString, buffer.start, buffer.length).leakRef();
-        location->setHash(hash);
-        location->setIsAtomic(true);
+        return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters16() + buffer.start, buffer.length);
     }
+
+    static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
+    {
+        return WTF::equal(string, buffer.baseString->characters16() + buffer.start, buffer.length);
+    }
 };
 
 PassRefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start, unsigned length)
 {
     if (!baseString)
-        return 0;
+        return nullptr;
 
     if (!length || start >= baseString->length())
         return StringImpl::empty();
@@ -315,7 +330,9 @@
     }
 
     SubstringLocation buffer = { baseString, start, length };
-    return addToStringTable<SubstringLocation, SubstringTranslator>(buffer);
+    if (baseString->is8Bit())
+        return addToStringTable<SubstringLocation, SubstringTranslator8>(buffer);
+    return addToStringTable<SubstringLocation, SubstringTranslator16>(buffer);
 }
     
 typedef HashTranslatorCharBuffer<LChar> LCharBuffer;

Modified: trunk/Source/WTF/wtf/text/Base64.cpp (165791 => 165792)


--- trunk/Source/WTF/wtf/text/Base64.cpp	2014-03-18 02:45:24 UTC (rev 165791)
+++ trunk/Source/WTF/wtf/text/Base64.cpp	2014-03-18 03:00:06 UTC (rev 165792)
@@ -250,7 +250,10 @@
 
 bool base64Decode(const String& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
 {
-    return base64DecodeInternal<UChar>(in.deprecatedCharacters(), in.length(), out, policy, base64DecMap);
+    unsigned length = in.length();
+    if (!length || in.is8Bit())
+        return base64DecodeInternal(in.characters8(), length, out, policy, base64DecMap);
+    return base64DecodeInternal(in.characters16(), length, out, policy, base64DecMap);
 }
 
 bool base64Decode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
@@ -261,17 +264,20 @@
     if (in.size() > UINT_MAX)
         return false;
 
-    return base64DecodeInternal<char>(in.data(), in.size(), out, policy, base64DecMap);
+    return base64DecodeInternal(reinterpret_cast<const LChar*>(in.data()), in.size(), out, policy, base64DecMap);
 }
 
 bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
 {
-    return base64DecodeInternal<char>(data, len, out, policy, base64DecMap);
+    return base64DecodeInternal(reinterpret_cast<const LChar*>(data), len, out, policy, base64DecMap);
 }
 
 bool base64URLDecode(const String& in, SignedOrUnsignedCharVectorAdapter out)
 {
-    return base64DecodeInternal<UChar>(in.deprecatedCharacters(), in.length(), out, Base64FailOnInvalidCharacter, base64URLDecMap);
+    unsigned length = in.length();
+    if (!length || in.is8Bit())
+        return base64DecodeInternal(in.characters8(), length, out, Base64FailOnInvalidCharacter, base64URLDecMap);
+    return base64DecodeInternal(in.characters16(), length, out, Base64FailOnInvalidCharacter, base64URLDecMap);
 }
 
 bool base64URLDecode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out)
@@ -282,12 +288,12 @@
     if (in.size() > UINT_MAX)
         return false;
 
-    return base64DecodeInternal<char>(in.data(), in.size(), out, Base64FailOnInvalidCharacter, base64URLDecMap);
+    return base64DecodeInternal(reinterpret_cast<const LChar*>(in.data()), in.size(), out, Base64FailOnInvalidCharacter, base64URLDecMap);
 }
 
 bool base64URLDecode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out)
 {
-    return base64DecodeInternal<char>(data, len, out, Base64FailOnInvalidCharacter, base64URLDecMap);
+    return base64DecodeInternal(reinterpret_cast<const LChar*>(data), len, out, Base64FailOnInvalidCharacter, base64URLDecMap);
 }
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (165791 => 165792)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2014-03-18 02:45:24 UTC (rev 165791)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2014-03-18 03:00:06 UTC (rev 165792)
@@ -986,7 +986,7 @@
 
     // Optimization 1: fast case for strings of length 1.
     if (matchLength == 1)
-        return WTF::find(characters16(), length(), *matchString, index);
+        return WTF::find(deprecatedCharacters(), length(), *matchString, index);
 
     // Check index & matchLength are in range.
     if (index > length())

Modified: trunk/Source/WTF/wtf/unicode/UTF8.cpp (165791 => 165792)


--- trunk/Source/WTF/wtf/unicode/UTF8.cpp	2014-03-18 02:45:24 UTC (rev 165791)
+++ trunk/Source/WTF/wtf/unicode/UTF8.cpp	2014-03-18 03:00:06 UTC (rev 165792)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007, 2014 Apple Inc.  All rights reserved.
  * Copyright (C) 2010 Patrick Gansterer <[email protected]>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -420,10 +420,10 @@
     return stringHasher.hashWithTop8BitsMasked();
 }
 
-bool equalUTF16WithUTF8(const UChar* a, const UChar* aEnd, const char* b, const char* bEnd)
+bool equalUTF16WithUTF8(const UChar* a, const char* b, const char* bEnd)
 {
     while (b < bEnd) {
-        if (isASCII(*b)) {
+        if (isASCII(*a) || isASCII(*b)) {
             if (*a++ != *b++)
                 return false;
             continue;
@@ -435,7 +435,7 @@
             return false;
 
         if (!isLegalUTF8(reinterpret_cast<const unsigned char*>(b), utf8SequenceLength))
-            return 0;
+            return false;
 
         UChar32 character = readUTF8Sequence(b, utf8SequenceLength);
         ASSERT(!isASCII(character));
@@ -455,8 +455,34 @@
             return false;
     }
 
-    return a == aEnd;
+    return true;
 }
 
+bool equalLatin1WithUTF8(const LChar* a, const char* b, const char* bEnd)
+{
+    while (b < bEnd) {
+        if (isASCII(*a) || isASCII(*b)) {
+            if (*a++ != *b++)
+                return false;
+            continue;
+        }
+
+        if (b + 1 == bEnd)
+            return false;
+
+        if ((b[0] & 0xE0) != 0xC0 || (b[1] & 0xC0) != 0x80)
+            return false;
+
+        LChar character = ((b[0] & 0x1F) << 6) | (b[1] & 0x3F);
+
+        b += 2;
+
+        if (*a++ != character)
+            return false;
+    }
+
+    return true;
+}
+
 } // namespace Unicode
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/unicode/UTF8.h (165791 => 165792)


--- trunk/Source/WTF/wtf/unicode/UTF8.h	2014-03-18 02:45:24 UTC (rev 165791)
+++ trunk/Source/WTF/wtf/unicode/UTF8.h	2014-03-18 03:00:06 UTC (rev 165792)
@@ -77,7 +77,9 @@
 
     WTF_EXPORT_PRIVATE unsigned calculateStringHashAndLengthFromUTF8MaskingTop8Bits(const char* data, const char* dataEnd, unsigned& dataLength, unsigned& utf16Length);
 
-    WTF_EXPORT_PRIVATE bool equalUTF16WithUTF8(const UChar* a, const UChar* aEnd, const char* b, const char* bEnd);
+    // The caller of these functions already knows that the lengths are the same, so we omit an end argument for UTF-16 and Latin-1.
+    bool equalUTF16WithUTF8(const UChar* stringInUTF16, const char* stringInUTF8, const char* stringInUTF8End);
+    bool equalLatin1WithUTF8(const LChar* stringInLatin1, const char* stringInUTF8, const char* stringInUTF8End);
 
 } // namespace Unicode
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to