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

Side by Side Diff: src/runtime/runtime-i18n.cc

Issue 2173403002: Replace SmartArrayPointer<T> with unique_ptr<T[]> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 #ifdef V8_I18N_SUPPORT 6 #ifdef V8_I18N_SUPPORT
7 #include "src/runtime/runtime-utils.h" 7 #include "src/runtime/runtime-utils.h"
8 8
9 #include <memory>
10
9 #include "src/api.h" 11 #include "src/api.h"
10 #include "src/api-natives.h" 12 #include "src/api-natives.h"
11 #include "src/arguments.h" 13 #include "src/arguments.h"
12 #include "src/factory.h" 14 #include "src/factory.h"
13 #include "src/i18n.h" 15 #include "src/i18n.h"
14 #include "src/isolate-inl.h" 16 #include "src/isolate-inl.h"
15 #include "src/messages.h" 17 #include "src/messages.h"
16 18
17 #include "unicode/brkiter.h" 19 #include "unicode/brkiter.h"
18 #include "unicode/calendar.h" 20 #include "unicode/calendar.h"
(...skipping 19 matching lines...) Expand all
38 #include "unicode/unistr.h" 40 #include "unicode/unistr.h"
39 #include "unicode/unum.h" 41 #include "unicode/unum.h"
40 #include "unicode/uversion.h" 42 #include "unicode/uversion.h"
41 43
42 44
43 namespace v8 { 45 namespace v8 {
44 namespace internal { 46 namespace internal {
45 namespace { 47 namespace {
46 48
47 const UChar* GetUCharBufferFromFlat(const String::FlatContent& flat, 49 const UChar* GetUCharBufferFromFlat(const String::FlatContent& flat,
48 base::SmartArrayPointer<uc16>* dest, 50 std::unique_ptr<uc16[]>* dest,
49 int32_t length) { 51 int32_t length) {
50 DCHECK(flat.IsFlat()); 52 DCHECK(flat.IsFlat());
51 if (flat.IsOneByte()) { 53 if (flat.IsOneByte()) {
52 if (dest->is_empty()) { 54 if (!*dest) {
53 dest->Reset(NewArray<uc16>(length)); 55 dest->reset(NewArray<uc16>(length));
54 CopyChars(dest->get(), flat.ToOneByteVector().start(), length); 56 CopyChars(dest->get(), flat.ToOneByteVector().start(), length);
55 } 57 }
56 return reinterpret_cast<const UChar*>(dest->get()); 58 return reinterpret_cast<const UChar*>(dest->get());
57 } else { 59 } else {
58 return reinterpret_cast<const UChar*>(flat.ToUC16Vector().start()); 60 return reinterpret_cast<const UChar*>(flat.ToUC16Vector().start());
59 } 61 }
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 string2 = String::Flatten(string2); 573 string2 = String::Flatten(string2);
572 574
573 UCollationResult result; 575 UCollationResult result;
574 UErrorCode status = U_ZERO_ERROR; 576 UErrorCode status = U_ZERO_ERROR;
575 { 577 {
576 DisallowHeapAllocation no_gc; 578 DisallowHeapAllocation no_gc;
577 int32_t length1 = string1->length(); 579 int32_t length1 = string1->length();
578 int32_t length2 = string2->length(); 580 int32_t length2 = string2->length();
579 String::FlatContent flat1 = string1->GetFlatContent(); 581 String::FlatContent flat1 = string1->GetFlatContent();
580 String::FlatContent flat2 = string2->GetFlatContent(); 582 String::FlatContent flat2 = string2->GetFlatContent();
581 base::SmartArrayPointer<uc16> sap1; 583 std::unique_ptr<uc16[]> sap1;
582 base::SmartArrayPointer<uc16> sap2; 584 std::unique_ptr<uc16[]> sap2;
583 const UChar* string_val1 = GetUCharBufferFromFlat(flat1, &sap1, length1); 585 const UChar* string_val1 = GetUCharBufferFromFlat(flat1, &sap1, length1);
584 const UChar* string_val2 = GetUCharBufferFromFlat(flat2, &sap2, length2); 586 const UChar* string_val2 = GetUCharBufferFromFlat(flat2, &sap2, length2);
585 result = 587 result =
586 collator->compare(string_val1, length1, string_val2, length2, status); 588 collator->compare(string_val1, length1, string_val2, length2, status);
587 } 589 }
588 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation(); 590 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation();
589 591
590 return *isolate->factory()->NewNumberFromInt(result); 592 return *isolate->factory()->NewNumberFromInt(result);
591 } 593 }
592 594
(...skipping 13 matching lines...) Expand all
606 DCHECK(args.length() == 2); 608 DCHECK(args.length() == 2);
607 609
608 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); 610 CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
609 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]); 611 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]);
610 CHECK(form_id >= 0 && 612 CHECK(form_id >= 0 &&
611 static_cast<size_t>(form_id) < arraysize(normalizationForms)); 613 static_cast<size_t>(form_id) < arraysize(normalizationForms));
612 614
613 int length = s->length(); 615 int length = s->length();
614 s = String::Flatten(s); 616 s = String::Flatten(s);
615 icu::UnicodeString result; 617 icu::UnicodeString result;
616 base::SmartArrayPointer<uc16> sap; 618 std::unique_ptr<uc16[]> sap;
617 UErrorCode status = U_ZERO_ERROR; 619 UErrorCode status = U_ZERO_ERROR;
618 { 620 {
619 DisallowHeapAllocation no_gc; 621 DisallowHeapAllocation no_gc;
620 String::FlatContent flat = s->GetFlatContent(); 622 String::FlatContent flat = s->GetFlatContent();
621 const UChar* src = GetUCharBufferFromFlat(flat, &sap, length); 623 const UChar* src = GetUCharBufferFromFlat(flat, &sap, length);
622 icu::UnicodeString input(false, src, length); 624 icu::UnicodeString input(false, src, length);
623 // Getting a singleton. Should not free it. 625 // Getting a singleton. Should not free it.
624 const icu::Normalizer2* normalizer = 626 const icu::Normalizer2* normalizer =
625 icu::Normalizer2::getInstance(nullptr, normalizationForms[form_id].name, 627 icu::Normalizer2::getInstance(nullptr, normalizationForms[form_id].name,
626 normalizationForms[form_id].mode, status); 628 normalizationForms[form_id].mode, status);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 if (!break_iterator) return isolate->ThrowIllegalOperation(); 707 if (!break_iterator) return isolate->ThrowIllegalOperation();
706 708
707 icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>( 709 icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>(
708 break_iterator_holder->GetInternalField(1)); 710 break_iterator_holder->GetInternalField(1));
709 delete u_text; 711 delete u_text;
710 712
711 int length = text->length(); 713 int length = text->length();
712 text = String::Flatten(text); 714 text = String::Flatten(text);
713 DisallowHeapAllocation no_gc; 715 DisallowHeapAllocation no_gc;
714 String::FlatContent flat = text->GetFlatContent(); 716 String::FlatContent flat = text->GetFlatContent();
715 base::SmartArrayPointer<uc16> sap; 717 std::unique_ptr<uc16[]> sap;
716 const UChar* text_value = GetUCharBufferFromFlat(flat, &sap, length); 718 const UChar* text_value = GetUCharBufferFromFlat(flat, &sap, length);
717 u_text = new icu::UnicodeString(text_value, length); 719 u_text = new icu::UnicodeString(text_value, length);
718 break_iterator_holder->SetInternalField(1, reinterpret_cast<Smi*>(u_text)); 720 break_iterator_holder->SetInternalField(1, reinterpret_cast<Smi*>(u_text));
719 721
720 break_iterator->setText(*u_text); 722 break_iterator->setText(*u_text);
721 723
722 return isolate->heap()->undefined_value(); 724 return isolate->heap()->undefined_value();
723 } 725 }
724 726
725 727
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 819
818 // Greek uppercasing has to be done via transliteration. 820 // Greek uppercasing has to be done via transliteration.
819 // TODO(jshin): Drop this special-casing once ICU's regular case conversion 821 // TODO(jshin): Drop this special-casing once ICU's regular case conversion
820 // API supports Greek uppercasing. See 822 // API supports Greek uppercasing. See
821 // http://bugs.icu-project.org/trac/ticket/10582 . 823 // http://bugs.icu-project.org/trac/ticket/10582 .
822 // In the meantime, if there's no Greek character in |s|, call this 824 // In the meantime, if there's no Greek character in |s|, call this
823 // function again with the root locale (lang=""). 825 // function again with the root locale (lang="").
824 // ICU's C API for transliteration is nasty and we just use C++ API. 826 // ICU's C API for transliteration is nasty and we just use C++ API.
825 if (V8_UNLIKELY(is_to_upper && lang[0] == 'e' && lang[1] == 'l')) { 827 if (V8_UNLIKELY(is_to_upper && lang[0] == 'e' && lang[1] == 'l')) {
826 icu::UnicodeString converted; 828 icu::UnicodeString converted;
827 base::SmartArrayPointer<uc16> sap; 829 std::unique_ptr<uc16[]> sap;
828 { 830 {
829 DisallowHeapAllocation no_gc; 831 DisallowHeapAllocation no_gc;
830 String::FlatContent flat = s->GetFlatContent(); 832 String::FlatContent flat = s->GetFlatContent();
831 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); 833 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length);
832 // Starts with the source string (read-only alias with copy-on-write 834 // Starts with the source string (read-only alias with copy-on-write
833 // semantics) and will be modified to contain the converted result. 835 // semantics) and will be modified to contain the converted result.
834 // Using read-only alias at first saves one copy operation if 836 // Using read-only alias at first saves one copy operation if
835 // transliteration does not change the input, which is rather rare. 837 // transliteration does not change the input, which is rather rare.
836 // Moreover, transliteration takes rather long so that saving one copy 838 // Moreover, transliteration takes rather long so that saving one copy
837 // helps only a little bit. 839 // helps only a little bit.
838 converted.setTo(false, src, src_length); 840 converted.setTo(false, src, src_length);
839 ConvertCaseWithTransliterator(&converted, "el-Upper"); 841 ConvertCaseWithTransliterator(&converted, "el-Upper");
840 // If no change is made, just return |s|. 842 // If no change is made, just return |s|.
841 if (converted.getBuffer() == src) return *s; 843 if (converted.getBuffer() == src) return *s;
842 } 844 }
843 RETURN_RESULT_OR_FAILURE( 845 RETURN_RESULT_OR_FAILURE(
844 isolate, 846 isolate,
845 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( 847 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>(
846 reinterpret_cast<const uint16_t*>(converted.getBuffer()), 848 reinterpret_cast<const uint16_t*>(converted.getBuffer()),
847 converted.length()))); 849 converted.length())));
848 } 850 }
849 851
850 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower; 852 auto case_converter = is_to_upper ? u_strToUpper : u_strToLower;
851 853
852 int32_t dest_length = src_length; 854 int32_t dest_length = src_length;
853 UErrorCode status; 855 UErrorCode status;
854 Handle<SeqTwoByteString> result; 856 Handle<SeqTwoByteString> result;
855 base::SmartArrayPointer<uc16> sap; 857 std::unique_ptr<uc16[]> sap;
856 858
857 // This is not a real loop. It'll be executed only once (no overflow) or 859 // This is not a real loop. It'll be executed only once (no overflow) or
858 // twice (overflow). 860 // twice (overflow).
859 for (int i = 0; i < 2; ++i) { 861 for (int i = 0; i < 2; ++i) {
860 result = 862 result =
861 isolate->factory()->NewRawTwoByteString(dest_length).ToHandleChecked(); 863 isolate->factory()->NewRawTwoByteString(dest_length).ToHandleChecked();
862 DisallowHeapAllocation no_gc; 864 DisallowHeapAllocation no_gc;
863 String::FlatContent flat = s->GetFlatContent(); 865 String::FlatContent flat = s->GetFlatContent();
864 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length); 866 const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length);
865 status = U_ZERO_ERROR; 867 status = U_ZERO_ERROR;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 Handle<FixedArray> date_cache_version = 1151 Handle<FixedArray> date_cache_version =
1150 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( 1152 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton(
1151 EternalHandles::DATE_CACHE_VERSION)); 1153 EternalHandles::DATE_CACHE_VERSION));
1152 return date_cache_version->get(0); 1154 return date_cache_version->get(0);
1153 } 1155 }
1154 1156
1155 } // namespace internal 1157 } // namespace internal
1156 } // namespace v8 1158 } // namespace v8
1157 1159
1158 #endif // V8_I18N_SUPPORT 1160 #endif // V8_I18N_SUPPORT
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698