| 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 13409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13420 NoGCScope no_gc; | 13420 NoGCScope no_gc; |
| 13421 if (length > 0) { | 13421 if (length > 0) { |
| 13422 uint8_t* dest = &result->ptr()->data_[0]; | 13422 uint8_t* dest = &result->ptr()->data_[0]; |
| 13423 uint8_t* src = &raw_ptr(str)->data_[begin_index]; | 13423 uint8_t* src = &raw_ptr(str)->data_[begin_index]; |
| 13424 memmove(dest, src, length); | 13424 memmove(dest, src, length); |
| 13425 } | 13425 } |
| 13426 return result; | 13426 return result; |
| 13427 } | 13427 } |
| 13428 | 13428 |
| 13429 | 13429 |
| 13430 void OneByteString::SetPeer(const String& str, |
| 13431 void* peer, |
| 13432 Dart_PeerFinalizer cback) { |
| 13433 ASSERT(!str.IsNull() && str.IsOneByteString()); |
| 13434 ASSERT(peer != NULL); |
| 13435 ExternalStringData<uint8_t>* ext_data = |
| 13436 new ExternalStringData<uint8_t>(NULL, peer, cback); |
| 13437 AddFinalizer(str, ext_data, OneByteString::Finalize); |
| 13438 } |
| 13439 |
| 13440 |
| 13441 void OneByteString::Finalize(Dart_WeakPersistentHandle handle, void* peer) { |
| 13442 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 13443 DeleteWeakPersistentHandle(handle); |
| 13444 } |
| 13445 |
| 13446 |
| 13430 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { | 13447 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { |
| 13431 intptr_t len = str.Length(); | 13448 intptr_t len = str.Length(); |
| 13432 if (len > 0) { | 13449 if (len > 0) { |
| 13433 intptr_t num_escapes = 0; | 13450 intptr_t num_escapes = 0; |
| 13434 intptr_t index = 0; | 13451 intptr_t index = 0; |
| 13435 for (intptr_t i = 0; i < len; i++) { | 13452 for (intptr_t i = 0; i < len; i++) { |
| 13436 if (IsSpecialCharacter(*CharAddr(str, i))) { | 13453 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 13437 num_escapes += 1; | 13454 num_escapes += 1; |
| 13438 } | 13455 } |
| 13439 } | 13456 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13572 } else { | 13589 } else { |
| 13573 ASSERT(len == 2); | 13590 ASSERT(len == 2); |
| 13574 Utf16::Encode(dst, CharAddr(result, i)); | 13591 Utf16::Encode(dst, CharAddr(result, i)); |
| 13575 } | 13592 } |
| 13576 i += len; | 13593 i += len; |
| 13577 } | 13594 } |
| 13578 return TwoByteString::raw(result); | 13595 return TwoByteString::raw(result); |
| 13579 } | 13596 } |
| 13580 | 13597 |
| 13581 | 13598 |
| 13599 void TwoByteString::SetPeer(const String& str, |
| 13600 void* peer, |
| 13601 Dart_PeerFinalizer cback) { |
| 13602 ASSERT(!str.IsNull() && str.IsTwoByteString()); |
| 13603 ASSERT(peer != NULL); |
| 13604 ExternalStringData<uint16_t>* ext_data = |
| 13605 new ExternalStringData<uint16_t>(NULL, peer, cback); |
| 13606 AddFinalizer(str, ext_data, TwoByteString::Finalize); |
| 13607 } |
| 13608 |
| 13609 |
| 13610 void TwoByteString::Finalize(Dart_WeakPersistentHandle handle, void* peer) { |
| 13611 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 13612 DeleteWeakPersistentHandle(handle); |
| 13613 } |
| 13614 |
| 13615 |
| 13582 RawExternalOneByteString* ExternalOneByteString::New( | 13616 RawExternalOneByteString* ExternalOneByteString::New( |
| 13583 const uint8_t* data, | 13617 const uint8_t* data, |
| 13584 intptr_t len, | 13618 intptr_t len, |
| 13585 void* peer, | 13619 void* peer, |
| 13586 Dart_PeerFinalizer callback, | 13620 Dart_PeerFinalizer callback, |
| 13587 Heap::Space space) { | 13621 Heap::Space space) { |
| 13588 ASSERT(Isolate::Current()->object_store()-> | 13622 ASSERT(Isolate::Current()->object_store()-> |
| 13589 external_one_byte_string_class() != Class::null()); | 13623 external_one_byte_string_class() != Class::null()); |
| 13590 if (len < 0 || len > kMaxElements) { | 13624 if (len < 0 || len > kMaxElements) { |
| 13591 // This should be caught before we reach here. | 13625 // This should be caught before we reach here. |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14738 } | 14772 } |
| 14739 | 14773 |
| 14740 | 14774 |
| 14741 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14775 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14742 stream->OpenObject(); | 14776 stream->OpenObject(); |
| 14743 stream->CloseObject(); | 14777 stream->CloseObject(); |
| 14744 } | 14778 } |
| 14745 | 14779 |
| 14746 | 14780 |
| 14747 } // namespace dart | 14781 } // namespace dart |
| OLD | NEW |