Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 13267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13278 Heap::Space space) { | 13278 Heap::Space space) { |
| 13279 ASSERT(!str1.IsNull() && !str2.IsNull()); | 13279 ASSERT(!str1.IsNull() && !str2.IsNull()); |
| 13280 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize()); | 13280 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize()); |
| 13281 if (char_size == kTwoByteChar) { | 13281 if (char_size == kTwoByteChar) { |
| 13282 return TwoByteString::Concat(str1, str2, space); | 13282 return TwoByteString::Concat(str1, str2, space); |
| 13283 } | 13283 } |
| 13284 return OneByteString::Concat(str1, str2, space); | 13284 return OneByteString::Concat(str1, str2, space); |
| 13285 } | 13285 } |
| 13286 | 13286 |
| 13287 | 13287 |
| 13288 | |
|
siva
2013/09/30 18:27:21
extra blank line.
srdjan
2013/10/01 14:57:44
Done.
| |
| 13288 RawString* String::ConcatAll(const Array& strings, | 13289 RawString* String::ConcatAll(const Array& strings, |
| 13289 Heap::Space space) { | 13290 Heap::Space space) { |
| 13291 return ConcatAllRange(strings, 0, strings.Length(), space); | |
| 13292 } | |
| 13293 | |
| 13294 | |
| 13295 RawString* String::ConcatAllRange(const Array& strings, | |
| 13296 intptr_t start, | |
| 13297 intptr_t end, | |
| 13298 Heap::Space space) { | |
| 13290 ASSERT(!strings.IsNull()); | 13299 ASSERT(!strings.IsNull()); |
| 13300 ASSERT(start >= 0); | |
| 13301 ASSERT(end <= strings.Length()); | |
| 13291 intptr_t result_len = 0; | 13302 intptr_t result_len = 0; |
| 13292 intptr_t strings_len = strings.Length(); | |
| 13293 String& str = String::Handle(); | 13303 String& str = String::Handle(); |
| 13294 intptr_t char_size = kOneByteChar; | 13304 intptr_t char_size = kOneByteChar; |
| 13295 for (intptr_t i = 0; i < strings_len; i++) { | 13305 // Compute 'char_size' and 'result_len'. |
| 13306 for (intptr_t i = start; i < end; i++) { | |
| 13296 str ^= strings.At(i); | 13307 str ^= strings.At(i); |
| 13297 intptr_t str_len = str.Length(); | 13308 const intptr_t str_len = str.Length(); |
| 13298 if ((kMaxElements - result_len) < str_len) { | 13309 if ((kMaxElements - result_len) < str_len) { |
| 13299 Isolate* isolate = Isolate::Current(); | 13310 Isolate* isolate = Isolate::Current(); |
| 13300 const Instance& exception = | 13311 const Instance& exception = |
| 13301 Instance::Handle(isolate->object_store()->out_of_memory()); | 13312 Instance::Handle(isolate->object_store()->out_of_memory()); |
| 13302 Exceptions::Throw(exception); | 13313 Exceptions::Throw(exception); |
| 13303 UNREACHABLE(); | 13314 UNREACHABLE(); |
| 13304 } | 13315 } |
| 13305 result_len += str_len; | 13316 result_len += str_len; |
| 13306 char_size = Utils::Maximum(char_size, str.CharSize()); | 13317 char_size = Utils::Maximum(char_size, str.CharSize()); |
| 13307 } | 13318 } |
| 13308 if (char_size == kOneByteChar) { | 13319 if (char_size == kOneByteChar) { |
| 13309 return OneByteString::ConcatAll(strings, result_len, space); | 13320 return OneByteString::ConcatAll(strings, start, end, result_len, space); |
| 13310 } | 13321 } |
| 13311 ASSERT(char_size == kTwoByteChar); | 13322 ASSERT(char_size == kTwoByteChar); |
| 13312 return TwoByteString::ConcatAll(strings, result_len, space); | 13323 return TwoByteString::ConcatAll(strings, start, end, result_len, space); |
| 13313 } | 13324 } |
| 13314 | 13325 |
| 13315 | 13326 |
| 13316 RawString* String::SubString(const String& str, | 13327 RawString* String::SubString(const String& str, |
| 13317 intptr_t begin_index, | 13328 intptr_t begin_index, |
| 13318 Heap::Space space) { | 13329 Heap::Space space) { |
| 13319 ASSERT(!str.IsNull()); | 13330 ASSERT(!str.IsNull()); |
| 13320 if (begin_index >= str.Length()) { | 13331 if (begin_index >= str.Length()) { |
| 13321 return String::null(); | 13332 return String::null(); |
| 13322 } | 13333 } |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13764 intptr_t len2 = str2.Length(); | 13775 intptr_t len2 = str2.Length(); |
| 13765 intptr_t len = len1 + len2; | 13776 intptr_t len = len1 + len2; |
| 13766 const String& result = String::Handle(OneByteString::New(len, space)); | 13777 const String& result = String::Handle(OneByteString::New(len, space)); |
| 13767 String::Copy(result, 0, str1, 0, len1); | 13778 String::Copy(result, 0, str1, 0, len1); |
| 13768 String::Copy(result, len1, str2, 0, len2); | 13779 String::Copy(result, len1, str2, 0, len2); |
| 13769 return OneByteString::raw(result); | 13780 return OneByteString::raw(result); |
| 13770 } | 13781 } |
| 13771 | 13782 |
| 13772 | 13783 |
| 13773 RawOneByteString* OneByteString::ConcatAll(const Array& strings, | 13784 RawOneByteString* OneByteString::ConcatAll(const Array& strings, |
| 13785 intptr_t start, | |
| 13786 intptr_t end, | |
| 13774 intptr_t len, | 13787 intptr_t len, |
| 13775 Heap::Space space) { | 13788 Heap::Space space) { |
| 13789 ASSERT(!strings.IsNull()); | |
| 13790 ASSERT(start >= 0); | |
| 13791 ASSERT(end <= strings.Length()); | |
| 13776 const String& result = String::Handle(OneByteString::New(len, space)); | 13792 const String& result = String::Handle(OneByteString::New(len, space)); |
| 13777 String& str = String::Handle(); | 13793 String& str = String::Handle(); |
| 13778 intptr_t strings_len = strings.Length(); | |
| 13779 intptr_t pos = 0; | 13794 intptr_t pos = 0; |
| 13780 for (intptr_t i = 0; i < strings_len; i++) { | 13795 for (intptr_t i = start; i < end; i++) { |
| 13781 str ^= strings.At(i); | 13796 str ^= strings.At(i); |
| 13782 intptr_t str_len = str.Length(); | 13797 const intptr_t str_len = str.Length(); |
| 13783 String::Copy(result, pos, str, 0, str_len); | 13798 String::Copy(result, pos, str, 0, str_len); |
| 13784 ASSERT((kMaxElements - pos) >= str_len); | 13799 ASSERT((kMaxElements - pos) >= str_len); |
| 13785 pos += str_len; | 13800 pos += str_len; |
| 13786 } | 13801 } |
| 13787 return OneByteString::raw(result); | 13802 return OneByteString::raw(result); |
| 13788 } | 13803 } |
| 13789 | 13804 |
| 13790 | 13805 |
| 13791 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), | 13806 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), |
| 13792 const String& str, | 13807 const String& str, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13946 intptr_t len2 = str2.Length(); | 13961 intptr_t len2 = str2.Length(); |
| 13947 intptr_t len = len1 + len2; | 13962 intptr_t len = len1 + len2; |
| 13948 const String& result = String::Handle(TwoByteString::New(len, space)); | 13963 const String& result = String::Handle(TwoByteString::New(len, space)); |
| 13949 String::Copy(result, 0, str1, 0, len1); | 13964 String::Copy(result, 0, str1, 0, len1); |
| 13950 String::Copy(result, len1, str2, 0, len2); | 13965 String::Copy(result, len1, str2, 0, len2); |
| 13951 return TwoByteString::raw(result); | 13966 return TwoByteString::raw(result); |
| 13952 } | 13967 } |
| 13953 | 13968 |
| 13954 | 13969 |
| 13955 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, | 13970 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, |
| 13971 intptr_t start, | |
| 13972 intptr_t end, | |
| 13956 intptr_t len, | 13973 intptr_t len, |
| 13957 Heap::Space space) { | 13974 Heap::Space space) { |
| 13975 ASSERT(!strings.IsNull()); | |
| 13976 ASSERT(start >= 0); | |
| 13977 ASSERT(end <= strings.Length()); | |
| 13958 const String& result = String::Handle(TwoByteString::New(len, space)); | 13978 const String& result = String::Handle(TwoByteString::New(len, space)); |
| 13959 String& str = String::Handle(); | 13979 String& str = String::Handle(); |
| 13960 intptr_t strings_len = strings.Length(); | |
| 13961 intptr_t pos = 0; | 13980 intptr_t pos = 0; |
| 13962 for (intptr_t i = 0; i < strings_len; i++) { | 13981 for (intptr_t i = start; i < end; i++) { |
| 13963 str ^= strings.At(i); | 13982 str ^= strings.At(i); |
| 13964 intptr_t str_len = str.Length(); | 13983 intptr_t str_len = str.Length(); |
|
siva
2013/09/30 18:27:21
const intrptr_t str_len
srdjan
2013/10/01 14:57:44
Done.
| |
| 13965 String::Copy(result, pos, str, 0, str_len); | 13984 String::Copy(result, pos, str, 0, str_len); |
| 13966 ASSERT((kMaxElements - pos) >= str_len); | 13985 ASSERT((kMaxElements - pos) >= str_len); |
| 13967 pos += str_len; | 13986 pos += str_len; |
| 13968 } | 13987 } |
| 13969 return TwoByteString::raw(result); | 13988 return TwoByteString::raw(result); |
| 13970 } | 13989 } |
| 13971 | 13990 |
| 13972 | 13991 |
| 13973 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), | 13992 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), |
| 13974 const String& str, | 13993 const String& str, |
| (...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15180 return "_MirrorReference"; | 15199 return "_MirrorReference"; |
| 15181 } | 15200 } |
| 15182 | 15201 |
| 15183 | 15202 |
| 15184 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15203 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 15185 JSONObject jsobj(stream); | 15204 JSONObject jsobj(stream); |
| 15186 } | 15205 } |
| 15187 | 15206 |
| 15188 | 15207 |
| 15189 } // namespace dart | 15208 } // namespace dart |
| OLD | NEW |