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

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: Addressed comments, PTAL. 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
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
srdjan 2013/03/07 17:58:34 Please restore line
Lasse Reichstein Nielsen 2013/03/08 07:18:44 Done. *And* saving the buffer this time.
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, 3) {
200 GET_NON_NULL_NATIVE_ARGUMENT(Uint16Array, a, arguments->NativeArgAt(0));
Vyacheslav Egorov (Google) 2013/03/07 13:50:52 I'd give a longer name to a.
Lasse Reichstein Nielsen 2013/03/08 07:18:44 Done.
201 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smiLength, arguments->NativeArgAt(1));
Vyacheslav Egorov (Google) 2013/03/07 13:50:52 smiLength -> length
Lasse Reichstein Nielsen 2013/03/08 07:18:44 Done.
202 GET_NON_NULL_NATIVE_ARGUMENT(Bool, isLatin1, arguments->NativeArgAt(2));
203 intptr_t array_len = a.Length();
204 int32_t length = smiLength.Value();
Vyacheslav Egorov (Google) 2013/03/07 13:50:52 length -> length_value
srdjan 2013/03/07 17:58:34 intr32_t -> intptr_t; on x64 Smi is greater than i
Lasse Reichstein Nielsen 2013/03/08 07:18:44 Done.
205 if (length < 0 || length > array_len) {
206 const Array& args = Array::Handle(Array::New(1));
207 args.SetAt(0, smiLength);
208 Exceptions::ThrowByType(Exceptions::kRange, args);
209 }
210 const String& result = isLatin1.value()
211 ? String::Handle(OneByteString::New(length, Heap::kNew))
212 : String::Handle(TwoByteString::New(length, Heap::kNew));
213 NoGCScope no_gc;
214 uint16_t* data_position = reinterpret_cast<uint16_t*>(
Vyacheslav Egorov (Google) 2013/03/07 13:50:52 consider a.ByteAddr(0)
Lasse Reichstein Nielsen 2013/03/08 07:18:44 I already tried that, but it seems to be private o
Ivan Posva 2013/03/08 09:15:41 I told Lasse to make the ByteAddr public. This is
Lasse Reichstein Nielsen 2013/03/08 10:19:37 And it works with a public ByteAddr.
215 reinterpret_cast<char*>(a.raw()) +
216 Uint16Array::data_offset() - kHeapObjectTag);
217 String::Copy(result, 0, data_position, length);
218 return result.raw();
219 }
220
200 } // namespace dart 221 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698