| 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 13332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13343 NoGCScope no_gc; | 13343 NoGCScope no_gc; |
| 13344 if (length > 0) { | 13344 if (length > 0) { |
| 13345 uint8_t* dest = &result->ptr()->data_[0]; | 13345 uint8_t* dest = &result->ptr()->data_[0]; |
| 13346 uint8_t* src = &raw_ptr(str)->data_[begin_index]; | 13346 uint8_t* src = &raw_ptr(str)->data_[begin_index]; |
| 13347 memmove(dest, src, length); | 13347 memmove(dest, src, length); |
| 13348 } | 13348 } |
| 13349 return result; | 13349 return result; |
| 13350 } | 13350 } |
| 13351 | 13351 |
| 13352 | 13352 |
| 13353 void OneByteString::SetPeer(const String& str, |
| 13354 void* peer, |
| 13355 Dart_PeerFinalizer cback) { |
| 13356 ASSERT(!str.IsNull() && str.IsOneByteString()); |
| 13357 ASSERT(peer != NULL); |
| 13358 ExternalStringData<uint8_t>* ext_data = |
| 13359 new ExternalStringData<uint8_t>(NULL, peer, cback); |
| 13360 AddFinalizer(str, ext_data, OneByteString::Finalize); |
| 13361 } |
| 13362 |
| 13363 |
| 13364 void OneByteString::Finalize(Dart_WeakPersistentHandle handle, void* peer) { |
| 13365 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 13366 DeleteWeakPersistentHandle(handle); |
| 13367 } |
| 13368 |
| 13369 |
| 13353 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { | 13370 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { |
| 13354 intptr_t len = str.Length(); | 13371 intptr_t len = str.Length(); |
| 13355 if (len > 0) { | 13372 if (len > 0) { |
| 13356 intptr_t num_escapes = 0; | 13373 intptr_t num_escapes = 0; |
| 13357 intptr_t index = 0; | 13374 intptr_t index = 0; |
| 13358 for (intptr_t i = 0; i < len; i++) { | 13375 for (intptr_t i = 0; i < len; i++) { |
| 13359 if (IsSpecialCharacter(*CharAddr(str, i))) { | 13376 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13360 num_escapes += 1; | 13377 num_escapes += 1; |
| 13361 } | 13378 } |
| 13362 } | 13379 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13495 } else { | 13512 } else { |
| 13496 ASSERT(len == 2); | 13513 ASSERT(len == 2); |
| 13497 Utf16::Encode(dst, CharAddr(result, i)); | 13514 Utf16::Encode(dst, CharAddr(result, i)); |
| 13498 } | 13515 } |
| 13499 i += len; | 13516 i += len; |
| 13500 } | 13517 } |
| 13501 return TwoByteString::raw(result); | 13518 return TwoByteString::raw(result); |
| 13502 } | 13519 } |
| 13503 | 13520 |
| 13504 | 13521 |
| 13522 void TwoByteString::SetPeer(const String& str, |
| 13523 void* peer, |
| 13524 Dart_PeerFinalizer cback) { |
| 13525 ASSERT(!str.IsNull() && str.IsTwoByteString()); |
| 13526 ASSERT(peer != NULL); |
| 13527 ExternalStringData<uint16_t>* ext_data = |
| 13528 new ExternalStringData<uint16_t>(NULL, peer, cback); |
| 13529 AddFinalizer(str, ext_data, TwoByteString::Finalize); |
| 13530 } |
| 13531 |
| 13532 |
| 13533 void TwoByteString::Finalize(Dart_WeakPersistentHandle handle, void* peer) { |
| 13534 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 13535 DeleteWeakPersistentHandle(handle); |
| 13536 } |
| 13537 |
| 13538 |
| 13505 RawExternalOneByteString* ExternalOneByteString::New( | 13539 RawExternalOneByteString* ExternalOneByteString::New( |
| 13506 const uint8_t* data, | 13540 const uint8_t* data, |
| 13507 intptr_t len, | 13541 intptr_t len, |
| 13508 void* peer, | 13542 void* peer, |
| 13509 Dart_PeerFinalizer callback, | 13543 Dart_PeerFinalizer callback, |
| 13510 Heap::Space space) { | 13544 Heap::Space space) { |
| 13511 ASSERT(Isolate::Current()->object_store()-> | 13545 ASSERT(Isolate::Current()->object_store()-> |
| 13512 external_one_byte_string_class() != Class::null()); | 13546 external_one_byte_string_class() != Class::null()); |
| 13513 if (len < 0 || len > kMaxElements) { | 13547 if (len < 0 || len > kMaxElements) { |
| 13514 // This should be caught before we reach here. | 13548 // This should be caught before we reach here. |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14661 } | 14695 } |
| 14662 | 14696 |
| 14663 | 14697 |
| 14664 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14698 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14665 stream->OpenObject(); | 14699 stream->OpenObject(); |
| 14666 stream->CloseObject(); | 14700 stream->CloseObject(); |
| 14667 } | 14701 } |
| 14668 | 14702 |
| 14669 | 14703 |
| 14670 } // namespace dart | 14704 } // namespace dart |
| OLD | NEW |