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

Side by Side Diff: runtime/vm/object.cc

Issue 25087006: Improve performance of string buffer by modifying concatAll native to allow growable array and an i… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13279 matching lines...) Expand 10 before | Expand all | Expand 10 after
13290 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize()); 13290 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize());
13291 if (char_size == kTwoByteChar) { 13291 if (char_size == kTwoByteChar) {
13292 return TwoByteString::Concat(str1, str2, space); 13292 return TwoByteString::Concat(str1, str2, space);
13293 } 13293 }
13294 return OneByteString::Concat(str1, str2, space); 13294 return OneByteString::Concat(str1, str2, space);
13295 } 13295 }
13296 13296
13297 13297
13298 RawString* String::ConcatAll(const Array& strings, 13298 RawString* String::ConcatAll(const Array& strings,
13299 Heap::Space space) { 13299 Heap::Space space) {
13300 return ConcatAllRange(strings, 0, strings.Length(), space);
13301 }
13302
13303
13304 RawString* String::ConcatAllRange(const Array& strings,
13305 intptr_t start,
13306 intptr_t end,
13307 Heap::Space space) {
13300 ASSERT(!strings.IsNull()); 13308 ASSERT(!strings.IsNull());
13309 ASSERT(start >= 0);
13310 ASSERT(end <= strings.Length());
13301 intptr_t result_len = 0; 13311 intptr_t result_len = 0;
13302 intptr_t strings_len = strings.Length();
13303 String& str = String::Handle(); 13312 String& str = String::Handle();
13304 intptr_t char_size = kOneByteChar; 13313 intptr_t char_size = kOneByteChar;
13305 for (intptr_t i = 0; i < strings_len; i++) { 13314 // Compute 'char_size' and 'result_len'.
13315 for (intptr_t i = start; i < end; i++) {
13306 str ^= strings.At(i); 13316 str ^= strings.At(i);
13307 intptr_t str_len = str.Length(); 13317 const intptr_t str_len = str.Length();
13308 if ((kMaxElements - result_len) < str_len) { 13318 if ((kMaxElements - result_len) < str_len) {
13309 Isolate* isolate = Isolate::Current(); 13319 Isolate* isolate = Isolate::Current();
13310 const Instance& exception = 13320 const Instance& exception =
13311 Instance::Handle(isolate->object_store()->out_of_memory()); 13321 Instance::Handle(isolate->object_store()->out_of_memory());
13312 Exceptions::Throw(exception); 13322 Exceptions::Throw(exception);
13313 UNREACHABLE(); 13323 UNREACHABLE();
13314 } 13324 }
13315 result_len += str_len; 13325 result_len += str_len;
13316 char_size = Utils::Maximum(char_size, str.CharSize()); 13326 char_size = Utils::Maximum(char_size, str.CharSize());
13317 } 13327 }
13318 if (char_size == kOneByteChar) { 13328 if (char_size == kOneByteChar) {
13319 return OneByteString::ConcatAll(strings, result_len, space); 13329 return OneByteString::ConcatAll(strings, start, end, result_len, space);
13320 } 13330 }
13321 ASSERT(char_size == kTwoByteChar); 13331 ASSERT(char_size == kTwoByteChar);
13322 return TwoByteString::ConcatAll(strings, result_len, space); 13332 return TwoByteString::ConcatAll(strings, start, end, result_len, space);
13323 } 13333 }
13324 13334
13325 13335
13326 RawString* String::SubString(const String& str, 13336 RawString* String::SubString(const String& str,
13327 intptr_t begin_index, 13337 intptr_t begin_index,
13328 Heap::Space space) { 13338 Heap::Space space) {
13329 ASSERT(!str.IsNull()); 13339 ASSERT(!str.IsNull());
13330 if (begin_index >= str.Length()) { 13340 if (begin_index >= str.Length()) {
13331 return String::null(); 13341 return String::null();
13332 } 13342 }
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
13803 intptr_t len2 = str2.Length(); 13813 intptr_t len2 = str2.Length();
13804 intptr_t len = len1 + len2; 13814 intptr_t len = len1 + len2;
13805 const String& result = String::Handle(OneByteString::New(len, space)); 13815 const String& result = String::Handle(OneByteString::New(len, space));
13806 String::Copy(result, 0, str1, 0, len1); 13816 String::Copy(result, 0, str1, 0, len1);
13807 String::Copy(result, len1, str2, 0, len2); 13817 String::Copy(result, len1, str2, 0, len2);
13808 return OneByteString::raw(result); 13818 return OneByteString::raw(result);
13809 } 13819 }
13810 13820
13811 13821
13812 RawOneByteString* OneByteString::ConcatAll(const Array& strings, 13822 RawOneByteString* OneByteString::ConcatAll(const Array& strings,
13823 intptr_t start,
13824 intptr_t end,
13813 intptr_t len, 13825 intptr_t len,
13814 Heap::Space space) { 13826 Heap::Space space) {
13827 ASSERT(!strings.IsNull());
13828 ASSERT(start >= 0);
13829 ASSERT(end <= strings.Length());
13815 const String& result = String::Handle(OneByteString::New(len, space)); 13830 const String& result = String::Handle(OneByteString::New(len, space));
13816 String& str = String::Handle(); 13831 String& str = String::Handle();
13817 intptr_t strings_len = strings.Length();
13818 intptr_t pos = 0; 13832 intptr_t pos = 0;
13819 for (intptr_t i = 0; i < strings_len; i++) { 13833 for (intptr_t i = start; i < end; i++) {
13820 str ^= strings.At(i); 13834 str ^= strings.At(i);
13821 intptr_t str_len = str.Length(); 13835 const intptr_t str_len = str.Length();
13822 String::Copy(result, pos, str, 0, str_len); 13836 String::Copy(result, pos, str, 0, str_len);
13823 ASSERT((kMaxElements - pos) >= str_len); 13837 ASSERT((kMaxElements - pos) >= str_len);
13824 pos += str_len; 13838 pos += str_len;
13825 } 13839 }
13826 return OneByteString::raw(result); 13840 return OneByteString::raw(result);
13827 } 13841 }
13828 13842
13829 13843
13830 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), 13844 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
13831 const String& str, 13845 const String& str,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
13985 intptr_t len2 = str2.Length(); 13999 intptr_t len2 = str2.Length();
13986 intptr_t len = len1 + len2; 14000 intptr_t len = len1 + len2;
13987 const String& result = String::Handle(TwoByteString::New(len, space)); 14001 const String& result = String::Handle(TwoByteString::New(len, space));
13988 String::Copy(result, 0, str1, 0, len1); 14002 String::Copy(result, 0, str1, 0, len1);
13989 String::Copy(result, len1, str2, 0, len2); 14003 String::Copy(result, len1, str2, 0, len2);
13990 return TwoByteString::raw(result); 14004 return TwoByteString::raw(result);
13991 } 14005 }
13992 14006
13993 14007
13994 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, 14008 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings,
14009 intptr_t start,
14010 intptr_t end,
13995 intptr_t len, 14011 intptr_t len,
13996 Heap::Space space) { 14012 Heap::Space space) {
14013 ASSERT(!strings.IsNull());
14014 ASSERT(start >= 0);
14015 ASSERT(end <= strings.Length());
13997 const String& result = String::Handle(TwoByteString::New(len, space)); 14016 const String& result = String::Handle(TwoByteString::New(len, space));
13998 String& str = String::Handle(); 14017 String& str = String::Handle();
13999 intptr_t strings_len = strings.Length();
14000 intptr_t pos = 0; 14018 intptr_t pos = 0;
14001 for (intptr_t i = 0; i < strings_len; i++) { 14019 for (intptr_t i = start; i < end; i++) {
14002 str ^= strings.At(i); 14020 str ^= strings.At(i);
14003 intptr_t str_len = str.Length(); 14021 const intptr_t str_len = str.Length();
14004 String::Copy(result, pos, str, 0, str_len); 14022 String::Copy(result, pos, str, 0, str_len);
14005 ASSERT((kMaxElements - pos) >= str_len); 14023 ASSERT((kMaxElements - pos) >= str_len);
14006 pos += str_len; 14024 pos += str_len;
14007 } 14025 }
14008 return TwoByteString::raw(result); 14026 return TwoByteString::raw(result);
14009 } 14027 }
14010 14028
14011 14029
14012 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), 14030 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch),
14013 const String& str, 14031 const String& str,
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
15219 return "_MirrorReference"; 15237 return "_MirrorReference";
15220 } 15238 }
15221 15239
15222 15240
15223 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15241 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15224 JSONObject jsobj(stream); 15242 JSONObject jsobj(stream);
15225 } 15243 }
15226 15244
15227 15245
15228 } // namespace dart 15246 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698