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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 10897014: Performance improvement for the Dart VM runtime method (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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) 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 } 1521 }
1522 1522
1523 1523
1524 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { 1524 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) {
1525 return RawObject::IsExternalStringClassId(Api::ClassId(object)); 1525 return RawObject::IsExternalStringClassId(Api::ClassId(object));
1526 } 1526 }
1527 1527
1528 1528
1529 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, 1529 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
1530 void** peer) { 1530 void** peer) {
1531 Isolate* isolate = Isolate::Current();
1532 DARTSCOPE(isolate);
1533 const String& str = Api::UnwrapStringHandle(isolate, object);
1534 if (str.IsNull()) {
1535 RETURN_TYPE_ERROR(isolate, object, String);
1536 }
1537 if (!str.IsExternal()) {
1538 return
1539 Api::NewError("%s expects argument 'object' to be an external String.",
1540 CURRENT_FUNC);
1541 }
1542 if (peer == NULL) { 1531 if (peer == NULL) {
1543 RETURN_NULL_ERROR(peer); 1532 RETURN_NULL_ERROR(peer);
1544 } 1533 }
1545 *peer = str.GetPeer(); 1534 // NoGCScope no_gc_scope;
1546 return Api::Success(isolate); 1535 if (Dart_IsExternalString(object)) {
Ivan Posva 2012/08/28 22:21:20 I would restructure this a bit to avoid duplicate
Tom Ball 2012/08/29 00:16:39 Thanks, this looks much cleaner -- done.
1536 Isolate* isolate = Isolate::Current();
1537 intptr_t class_id = Api::ClassId(object);
1538 void* raw_peer;
1539 switch (class_id) {
1540 case kExternalOneByteStringCid: {
1541 RawExternalOneByteString* raw_string =
1542 (*(reinterpret_cast<RawExternalOneByteString**>(object)))->ptr();
Ivan Posva 2012/08/28 22:21:20 Please do not reach into the internals of handles.
Tom Ball 2012/08/29 00:16:39 Done.
1543 ExternalStringData<uint8_t>* data = raw_string->external_data_;
1544 raw_peer = data != NULL ? data->peer() : NULL;
Ivan Posva 2012/08/28 22:21:20 This extra check for data being NULL is not necess
Tom Ball 2012/08/29 00:16:39 Done.
1545 break;
1546 }
1547 case kExternalTwoByteStringCid: {
1548 RawExternalTwoByteString* raw_string =
1549 (*(reinterpret_cast<RawExternalTwoByteString**>(object)))->ptr();
1550 ExternalStringData<uint16_t>* data = raw_string->external_data_;
1551 raw_peer = data != NULL ? data->peer() : NULL;
1552 break;
1553 }
1554 default: {
1555 RawExternalFourByteString* raw_string =
1556 (*(reinterpret_cast<RawExternalFourByteString**>(object)))->ptr();
1557 ExternalStringData<uint32_t>* data = raw_string->external_data_;
1558 raw_peer = data != NULL ? data->peer() : NULL;
1559 break;
1560 }
1561 }
1562 if (raw_peer != NULL) {
1563 *peer = raw_peer;
1564 return Api::Success(isolate);
1565 } else {
1566 RETURN_TYPE_ERROR(isolate, object, String);
1567 }
1568 }
1569 const char* error_msg = Dart_IsString(object) ?
1570 "%s expects argument 'object' to be an external String." :
1571 "%s expects argument 'object' to be of type String.";
1572 return Api::NewError(error_msg, CURRENT_FUNC);
1547 } 1573 }
1548 1574
1549 1575
1550 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, 1576 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints,
1551 intptr_t length, 1577 intptr_t length,
1552 void* peer, 1578 void* peer,
1553 Dart_PeerFinalizer callback) { 1579 Dart_PeerFinalizer callback) {
1554 Isolate* isolate = Isolate::Current(); 1580 Isolate* isolate = Isolate::Current();
1555 DARTSCOPE(isolate); 1581 DARTSCOPE(isolate);
1556 if (codepoints == NULL && length != 0) { 1582 if (codepoints == NULL && length != 0) {
(...skipping 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after
4131 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4157 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4132 Dart::set_perf_events_writer(function); 4158 Dart::set_perf_events_writer(function);
4133 } 4159 }
4134 4160
4135 4161
4136 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4162 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4137 Dart::set_flow_graph_writer(function); 4163 Dart::set_flow_graph_writer(function);
4138 } 4164 }
4139 4165
4140 } // namespace dart 4166 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698