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

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

Issue 10891036: Reworked previous CL (ExternalStringGetPeer speed up) to avoid the (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
« no previous file with comments | « no previous file | runtime/vm/raw_object.h » ('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) 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 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 CHECK_LENGTH(length, String::kMaxElements); 1519 CHECK_LENGTH(length, String::kMaxElements);
1520 return Api::NewHandle(isolate, String::New(codepoints, length)); 1520 return Api::NewHandle(isolate, String::New(codepoints, length));
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 bool ExternalStringGetPeerHelper(Dart_Handle object, void** peer) {
1530 NoGCScope no_gc_scope;
1531 RawObject* raw_obj = Api::UnwrapHandle(object);
1532 switch (Api::ClassId(object)) {
1533 case kExternalOneByteStringCid: {
1534 RawExternalOneByteString* raw_string =
1535 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr();
1536 ExternalStringData<uint8_t>* data = raw_string->external_data_;
1537 *peer = data->peer();
1538 return true;
1539 }
1540 case kExternalTwoByteStringCid: {
1541 RawExternalTwoByteString* raw_string =
1542 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
1543 ExternalStringData<uint16_t>* data = raw_string->external_data_;
1544 *peer = data->peer();
1545 return true;
1546 }
1547 case kExternalFourByteStringCid: {
1548 RawExternalFourByteString* raw_string =
1549 reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
1550 ExternalStringData<uint32_t>* data = raw_string->external_data_;
1551 *peer = data->peer();
1552 return true;
1553 }
1554 }
1555 return false;
1556 }
1557
1558
1529 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, 1559 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
1530 void** peer) { 1560 void** peer) {
1531 intptr_t class_id = Api::ClassId(object);
1532 if (peer == NULL) { 1561 if (peer == NULL) {
1533 RETURN_NULL_ERROR(peer); 1562 RETURN_NULL_ERROR(peer);
1534 } else { 1563 }
1535 NoGCScope no_gc_scope; 1564
1536 RawObject* raw_obj = Api::UnwrapHandle(object); 1565 if (ExternalStringGetPeerHelper(object, peer)) {
1537 switch (class_id) { 1566 return Api::Success(Isolate::Current());
1538 case kExternalOneByteStringCid: {
1539 RawExternalOneByteString* raw_string =
1540 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr();
1541 ExternalStringData<uint8_t>* data = raw_string->external_data_;
1542 *peer = data->peer();
1543 return Api::Success(Isolate::Current());
1544 }
1545 case kExternalTwoByteStringCid: {
1546 RawExternalTwoByteString* raw_string =
1547 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
1548 ExternalStringData<uint16_t>* data = raw_string->external_data_;
1549 *peer = data->peer();
1550 return Api::Success(Isolate::Current());
1551 }
1552 case kExternalFourByteStringCid: {
1553 RawExternalFourByteString* raw_string =
1554 reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
1555 ExternalStringData<uint32_t>* data = raw_string->external_data_;
1556 *peer = data->peer();
1557 return Api::Success(Isolate::Current());
1558 }
1559 }
1560 } 1567 }
1561 1568
1562 // It's not an external string, return appropriate error. 1569 // It's not an external string, return appropriate error.
1563 // Note: this is invoked outside of the NoGCScope'd block above, since 1570 // Note: this is invoked outside of the NoGCScope'd block above, since
1564 // error messages allocate new handles. 1571 // error messages allocate new handles.
1565 if (!RawObject::IsStringClassId(class_id)) { 1572 if (!RawObject::IsStringClassId(Api::ClassId(object))) {
1566 RETURN_TYPE_ERROR(Isolate::Current(), object, String); 1573 RETURN_TYPE_ERROR(Isolate::Current(), object, String);
1567 } else { 1574 } else {
1568 return 1575 return
1569 Api::NewError( 1576 Api::NewError(
1570 "%s expects argument 'object' to be an external String.", 1577 "%s expects argument 'object' to be an external String.",
1571 CURRENT_FUNC); 1578 CURRENT_FUNC);
1572 } 1579 }
1573 } 1580 }
1574 1581
1575 1582
(...skipping 2603 matching lines...) Expand 10 before | Expand all | Expand 10 after
4179 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4186 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4180 Dart::set_perf_events_writer(function); 4187 Dart::set_perf_events_writer(function);
4181 } 4188 }
4182 4189
4183 4190
4184 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4191 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4185 Dart::set_flow_graph_writer(function); 4192 Dart::set_flow_graph_writer(function);
4186 } 4193 }
4187 4194
4188 } // namespace dart 4195 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698