Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/platform/wtf/text/StringImpl.cpp

Issue 2813533003: Add "Unicode" suffixes to some functions of WTF::String and WTF::StringImpl. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 4 * (C) 2001 Dirk Mueller ( mueller@kde.org )
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All
6 * rights reserved. 6 * rights reserved.
7 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 7 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 UChar* data16; 626 UChar* data16;
627 RefPtr<StringImpl> new_impl = CreateUninitialized(length_, data16); 627 RefPtr<StringImpl> new_impl = CreateUninitialized(length_, data16);
628 628
629 for (unsigned i = 0; i < length; ++i) { 629 for (unsigned i = 0; i < length; ++i) {
630 UChar c = Characters16()[i]; 630 UChar c = Characters16()[i];
631 data16[i] = IsASCIIUpper(c) ? ToASCIILower(c) : c; 631 data16[i] = IsASCIIUpper(c) ? ToASCIILower(c) : c;
632 } 632 }
633 return new_impl.Release(); 633 return new_impl.Release();
634 } 634 }
635 635
636 PassRefPtr<StringImpl> StringImpl::Lower() { 636 PassRefPtr<StringImpl> StringImpl::LowerUnicode() {
637 // Note: This is a hot function in the Dromaeo benchmark, specifically the 637 // Note: This is a hot function in the Dromaeo benchmark, specifically the
638 // no-op code path up through the first 'return' statement. 638 // no-op code path up through the first 'return' statement.
639 639
640 // First scan the string for uppercase and non-ASCII characters: 640 // First scan the string for uppercase and non-ASCII characters:
641 if (Is8Bit()) { 641 if (Is8Bit()) {
642 unsigned first_index_to_be_lowered = length_; 642 unsigned first_index_to_be_lowered = length_;
643 for (unsigned i = 0; i < length_; ++i) { 643 for (unsigned i = 0; i < length_; ++i) {
644 LChar ch = Characters8()[i]; 644 LChar ch = Characters8()[i];
645 if (UNLIKELY(IsASCIIUpper(ch) || ch & ~0x7F)) { 645 if (UNLIKELY(IsASCIIUpper(ch) || ch & ~0x7F)) {
646 first_index_to_be_lowered = i; 646 first_index_to_be_lowered = i;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 if (!error && real_length == length) 703 if (!error && real_length == length)
704 return new_impl.Release(); 704 return new_impl.Release();
705 705
706 new_impl = CreateUninitialized(real_length, data16); 706 new_impl = CreateUninitialized(real_length, data16);
707 Unicode::ToLower(data16, real_length, Characters16(), length_, &error); 707 Unicode::ToLower(data16, real_length, Characters16(), length_, &error);
708 if (error) 708 if (error)
709 return this; 709 return this;
710 return new_impl.Release(); 710 return new_impl.Release();
711 } 711 }
712 712
713 PassRefPtr<StringImpl> StringImpl::Upper() { 713 PassRefPtr<StringImpl> StringImpl::UpperUnicode() {
714 // This function could be optimized for no-op cases the way lower() is, 714 // This function could be optimized for no-op cases the way LowerUnicode() is,
715 // but in empirical testing, few actual calls to upper() are no-ops, so 715 // but in empirical testing, few actual calls to UpperUnicode() are no-ops, so
716 // it wouldn't be worth the extra time for pre-scanning. 716 // it wouldn't be worth the extra time for pre-scanning.
717 717
718 RELEASE_ASSERT(length_ <= 718 RELEASE_ASSERT(length_ <=
719 static_cast<unsigned>(numeric_limits<int32_t>::max())); 719 static_cast<unsigned>(numeric_limits<int32_t>::max()));
720 int32_t length = length_; 720 int32_t length = length_;
721 721
722 if (Is8Bit()) { 722 if (Is8Bit()) {
723 LChar* data8; 723 LChar* data8;
724 RefPtr<StringImpl> new_impl = CreateUninitialized(length_, data8); 724 RefPtr<StringImpl> new_impl = CreateUninitialized(length_, data8);
725 725
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 return output->Substring(0, target_length); 864 return output->Substring(0, target_length);
865 return output.Release(); 865 return output.Release();
866 } 866 }
867 if (status != U_BUFFER_OVERFLOW_ERROR) 867 if (status != U_BUFFER_OVERFLOW_ERROR)
868 return original_string; 868 return original_string;
869 // Expand the buffer. 869 // Expand the buffer.
870 output = StringImpl::CreateUninitialized(target_length, data16); 870 output = StringImpl::CreateUninitialized(target_length, data16);
871 } while (true); 871 } while (true);
872 } 872 }
873 873
874 PassRefPtr<StringImpl> StringImpl::Lower( 874 PassRefPtr<StringImpl> StringImpl::LowerUnicode(
875 const AtomicString& locale_identifier) { 875 const AtomicString& locale_identifier) {
876 // Use the more optimized code path most of the time. 876 // Use the more optimized code path most of the time.
877 // Only Turkic (tr and az) languages and Lithuanian requires 877 // Only Turkic (tr and az) languages and Lithuanian requires
878 // locale-specific lowercasing rules. Even though CLDR has el-Lower, 878 // locale-specific lowercasing rules. Even though CLDR has el-Lower,
879 // it's identical to the locale-agnostic lowercasing. Context-dependent 879 // it's identical to the locale-agnostic lowercasing. Context-dependent
880 // handling of Greek capital sigma is built into the common lowercasing 880 // handling of Greek capital sigma is built into the common lowercasing
881 // function in ICU. 881 // function in ICU.
882 const char* locale_for_conversion = 0; 882 const char* locale_for_conversion = 0;
883 if (LocaleIdMatchesLang(locale_identifier, "tr") || 883 if (LocaleIdMatchesLang(locale_identifier, "tr") ||
884 LocaleIdMatchesLang(locale_identifier, "az")) 884 LocaleIdMatchesLang(locale_identifier, "az"))
885 locale_for_conversion = "tr"; 885 locale_for_conversion = "tr";
886 else if (LocaleIdMatchesLang(locale_identifier, "lt")) 886 else if (LocaleIdMatchesLang(locale_identifier, "lt"))
887 locale_for_conversion = "lt"; 887 locale_for_conversion = "lt";
888 else 888 else
889 return Lower(); 889 return LowerUnicode();
890 890
891 if (length_ > static_cast<unsigned>(numeric_limits<int32_t>::max())) 891 if (length_ > static_cast<unsigned>(numeric_limits<int32_t>::max()))
892 CRASH(); 892 CRASH();
893 int length = length_; 893 int length = length_;
894 894
895 RefPtr<StringImpl> upconverted = UpconvertedString(); 895 RefPtr<StringImpl> upconverted = UpconvertedString();
896 const UChar* source16 = upconverted->Characters16(); 896 const UChar* source16 = upconverted->Characters16();
897 return CaseConvert(source16, length, u_strToLower, locale_for_conversion, 897 return CaseConvert(source16, length, u_strToLower, locale_for_conversion,
898 this); 898 this);
899 } 899 }
900 900
901 PassRefPtr<StringImpl> StringImpl::Upper( 901 PassRefPtr<StringImpl> StringImpl::UpperUnicode(
902 const AtomicString& locale_identifier) { 902 const AtomicString& locale_identifier) {
903 // Use the more-optimized code path most of the time. 903 // Use the more-optimized code path most of the time.
904 // Only Turkic (tr and az) languages, Greek and Lithuanian require 904 // Only Turkic (tr and az) languages, Greek and Lithuanian require
905 // locale-specific uppercasing rules. 905 // locale-specific uppercasing rules.
906 const char* locale_for_conversion = 0; 906 const char* locale_for_conversion = 0;
907 if (LocaleIdMatchesLang(locale_identifier, "tr") || 907 if (LocaleIdMatchesLang(locale_identifier, "tr") ||
908 LocaleIdMatchesLang(locale_identifier, "az")) 908 LocaleIdMatchesLang(locale_identifier, "az"))
909 locale_for_conversion = "tr"; 909 locale_for_conversion = "tr";
910 else if (LocaleIdMatchesLang(locale_identifier, "el")) 910 else if (LocaleIdMatchesLang(locale_identifier, "el"))
911 locale_for_conversion = "el"; 911 locale_for_conversion = "el";
912 else if (LocaleIdMatchesLang(locale_identifier, "lt")) 912 else if (LocaleIdMatchesLang(locale_identifier, "lt"))
913 locale_for_conversion = "lt"; 913 locale_for_conversion = "lt";
914 else 914 else
915 return Upper(); 915 return UpperUnicode();
916 916
917 if (length_ > static_cast<unsigned>(numeric_limits<int32_t>::max())) 917 if (length_ > static_cast<unsigned>(numeric_limits<int32_t>::max()))
918 CRASH(); 918 CRASH();
919 int length = length_; 919 int length = length_;
920 920
921 RefPtr<StringImpl> upconverted = UpconvertedString(); 921 RefPtr<StringImpl> upconverted = UpconvertedString();
922 const UChar* source16 = upconverted->Characters16(); 922 const UChar* source16 = upconverted->Characters16();
923 923
924 return CaseConvert(source16, length, u_strToUpper, locale_for_conversion, 924 return CaseConvert(source16, length, u_strToUpper, locale_for_conversion,
925 this); 925 this);
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 } else if (LocaleIdMatchesLang(locale_identifier, "lt")) { 2246 } else if (LocaleIdMatchesLang(locale_identifier, "lt")) {
2247 // TODO(rob.buis) implement upper-casing rules for lt 2247 // TODO(rob.buis) implement upper-casing rules for lt
2248 // like in StringImpl::upper(locale). 2248 // like in StringImpl::upper(locale).
2249 } 2249 }
2250 } 2250 }
2251 2251
2252 return ToUpper(c); 2252 return ToUpper(c);
2253 } 2253 }
2254 2254
2255 } // namespace WTF 2255 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698