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

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

Issue 12421002: Change VM's string-buffer patch to use a Uin16Array as backing buffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « no previous file | runtime/lib/string_buffer_patch.dart » ('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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 } 43 }
44 utf32_array[i] = value; 44 utf32_array[i] = value;
45 } 45 }
46 if (is_one_byte_string) { 46 if (is_one_byte_string) {
47 return OneByteString::New(utf32_array, array_len, Heap::kNew); 47 return OneByteString::New(utf32_array, array_len, Heap::kNew);
48 } 48 }
49 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); 49 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew);
50 } 50 }
51 51
52
53 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) { 52 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) {
54 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); 53 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
55 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); 54 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1));
56 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); 55 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2));
57 56
58 intptr_t start = start_obj.Value(); 57 intptr_t start = start_obj.Value();
59 intptr_t end = end_obj.Value(); 58 intptr_t end = end_obj.Value();
60 return String::SubString(receiver, start, (end - start)); 59 return String::SubString(receiver, start, (end - start));
61 } 60 }
62 61
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 elem ^= strings.At(i); 189 elem ^= strings.At(i);
191 if (!elem.IsString()) { 190 if (!elem.IsString()) {
192 const Array& args = Array::Handle(Array::New(1)); 191 const Array& args = Array::Handle(Array::New(1));
193 args.SetAt(0, elem); 192 args.SetAt(0, elem);
194 Exceptions::ThrowByType(Exceptions::kArgument, args); 193 Exceptions::ThrowByType(Exceptions::kArgument, args);
195 } 194 }
196 } 195 }
197 return String::ConcatAll(strings); 196 return String::ConcatAll(strings);
198 } 197 }
199 198
199 DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 2) {
200 GET_NON_NULL_NATIVE_ARGUMENT(Uint16Array, a, arguments->NativeArgAt(0));
201 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smiLength, arguments->NativeArgAt(1));
202 intptr_t array_len = a.Length();
203 int32_t length = smiLength.Value();
204 if (length < 0 || length > array_len) {
205 const Array& args = Array::Handle(Array::New(1));
206 args.SetAt(0, smiLength);
207 Exceptions::ThrowByType(Exceptions::kRange, args);
208 }
209 // TODO(lrn): Pass parameter saying whether the data is Latin1, and
210 // use RawOneByteString::New/RawTwoByteString::New directly.
211 uint16_t* data_position = reinterpret_cast<uint16_t*>(
212 reinterpret_cast<char*>(a.raw()) +
213 Uint16Array::data_offset() - kHeapObjectTag);
214 return String::FromUTF16(data_position, length, Heap::kNew);
Vyacheslav Egorov (Google) 2013/03/05 14:44:32 This is not GC safe and is against VM guidelines.
215 }
216
200 } // namespace dart 217 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string_buffer_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698