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

Side by Side Diff: runtime/lib/string.cc

Issue 11308337: Improve C++ code for string splittig (Dromaeo benchmark). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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 | « no previous file | runtime/vm/object.h » ('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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ASSERT(receiver.IsOneByteString()); 67 ASSERT(receiver.IsOneByteString());
68 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); 68 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1));
69 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); 69 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2));
70 70
71 const intptr_t start = start_obj.Value(); 71 const intptr_t start = start_obj.Value();
72 const intptr_t end = end_obj.Value(); 72 const intptr_t end = end_obj.Value();
73 return OneByteString::New(receiver, start, end - start, Heap::kNew); 73 return OneByteString::New(receiver, start, end - start, Heap::kNew);
74 } 74 }
75 75
76 76
77 // This is high-performance code.
77 DEFINE_NATIVE_ENTRY(OneByteString_splitWithCharCode, 2) { 78 DEFINE_NATIVE_ENTRY(OneByteString_splitWithCharCode, 2) {
78 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); 79 const String& receiver = String::CheckedHandle(isolate,
80 arguments->NativeArgAt(0));
79 ASSERT(receiver.IsOneByteString()); 81 ASSERT(receiver.IsOneByteString());
80 GET_NATIVE_ARGUMENT(Smi, smi_split_code, arguments->NativeArgAt(1)); 82 GET_NATIVE_ARGUMENT(Smi, smi_split_code, arguments->NativeArgAt(1));
81 const intptr_t len = receiver.Length(); 83 const intptr_t len = receiver.Length();
82 const intptr_t split_code = smi_split_code.Value(); 84 const intptr_t split_code = smi_split_code.Value();
83 const GrowableObjectArray& result = GrowableObjectArray::Handle( 85 const GrowableObjectArray& result = GrowableObjectArray::Handle(
84 GrowableObjectArray::New(4, Heap::kNew)); 86 isolate,
85 String& str = String::Handle(); 87 GrowableObjectArray::New(16, Heap::kNew));
88 String& str = String::Handle(isolate);
86 intptr_t start = 0; 89 intptr_t start = 0;
87 intptr_t i = 0; 90 intptr_t i = 0;
88 for (; i < len; i++) { 91 for (; i < len; i++) {
89 if (split_code == receiver.CharAt(i)) { 92 if (split_code == OneByteString::CharAt(receiver, i)) {
90 str = String::SubString(receiver, start, (i - start)); 93 str = OneByteString::SubStringUnchecked(receiver,
91 result.Add(str); 94 start,
95 (i - start),
96 Heap::kNew);
97 result.Add(isolate, str);
92 start = i + 1; 98 start = i + 1;
93 } 99 }
94 } 100 }
95 str = String::SubString(receiver, start, (i - start)); 101 str = OneByteString::SubStringUnchecked(receiver,
96 result.Add(str); 102 start,
103 (i - start),
104 Heap::kNew);
105 result.Add(isolate, str);
97 return result.raw(); 106 return result.raw();
98 } 107 }
99 108
100 109
101 DEFINE_NATIVE_ENTRY(String_getHashCode, 1) { 110 DEFINE_NATIVE_ENTRY(String_getHashCode, 1) {
102 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); 111 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
103 intptr_t hash_val = receiver.Hash(); 112 intptr_t hash_val = receiver.Hash();
104 ASSERT(hash_val > 0); 113 ASSERT(hash_val > 0);
105 ASSERT(Smi::IsValid(hash_val)); 114 ASSERT(Smi::IsValid(hash_val));
106 return Smi::New(hash_val); 115 return Smi::New(hash_val);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (!elem.IsString()) { 193 if (!elem.IsString()) {
185 GrowableArray<const Object*> args; 194 GrowableArray<const Object*> args;
186 args.Add(&elem); 195 args.Add(&elem);
187 Exceptions::ThrowByType(Exceptions::kArgument, args); 196 Exceptions::ThrowByType(Exceptions::kArgument, args);
188 } 197 }
189 } 198 }
190 return String::ConcatAll(strings); 199 return String::ConcatAll(strings);
191 } 200 }
192 201
193 } // namespace dart 202 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698