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

Side by Side Diff: sdk/lib/io/common.dart

Issue 11418004: Don't copy Int8Arrays when passing them in as lists of bytes and don't (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « runtime/vm/dart_api_impl.cc ('k') | no next file » | 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 // Constants used when working with native ports. 5 // Constants used when working with native ports.
6 const int _SUCCESS_RESPONSE = 0; 6 const int _SUCCESS_RESPONSE = 0;
7 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; 7 const int _ILLEGAL_ARGUMENT_RESPONSE = 1;
8 const int _OSERROR_RESPONSE = 2; 8 const int _OSERROR_RESPONSE = 2;
9 const int _FILE_CLOSED_RESPONSE = 3; 9 const int _FILE_CLOSED_RESPONSE = 3;
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 List buffer; 61 List buffer;
62 int offset; 62 int offset;
63 } 63 }
64 64
65 // Ensure that the input List can be serialized through a native port. 65 // Ensure that the input List can be serialized through a native port.
66 // Only builtin Lists can be serialized through. If user-defined Lists 66 // Only builtin Lists can be serialized through. If user-defined Lists
67 // get here, the contents is copied to a Uint8List. This has the added 67 // get here, the contents is copied to a Uint8List. This has the added
68 // benefit that it is faster to access from the C code as well. 68 // benefit that it is faster to access from the C code as well.
69 _BufferAndOffset _ensureFastAndSerializableBuffer( 69 _BufferAndOffset _ensureFastAndSerializableBuffer(
70 List buffer, int offset, int bytes) { 70 List buffer, int offset, int bytes) {
71 if (buffer is Uint8List || _BufferUtils._isBuiltinList(buffer)) { 71 if (buffer is Uint8List ||
72 buffer is Int8List ||
73 _BufferUtils._isBuiltinList(buffer)) {
72 return new _BufferAndOffset(buffer, offset); 74 return new _BufferAndOffset(buffer, offset);
73 } 75 }
74 var newBuffer = new Uint8List(bytes); 76 var newBuffer = new Uint8List(bytes);
75 int j = offset; 77 int j = offset;
76 for (int i = 0; i < bytes; i++) { 78 for (int i = 0; i < bytes; i++) {
77 int value = buffer[j]; 79 int value = buffer[j];
78 if (value is! int) { 80 if (value is! int) {
79 throw new ArgumentError("List element is not an integer at index $j"); 81 throw new ArgumentError("List element is not an integer at index $j");
80 } 82 }
81 newBuffer[i] = value; 83 newBuffer[i] = value;
82 j++; 84 j++;
83 } 85 }
84 return new _BufferAndOffset(newBuffer, 0); 86 return new _BufferAndOffset(newBuffer, 0);
85 } 87 }
86 88
87 89
88 // TODO(ager): The only reason for the class here is that 90 // TODO(ager): The only reason for the class here is that
89 // we cannot patch a top-level function. 91 // we cannot patch a top-level function.
90 class _BufferUtils { 92 class _BufferUtils {
91 // Check if a List is a builtin VM List type. Returns true 93 // Check if a List is a builtin VM List type. Returns true
92 // if the List is a builtin VM List type and false if it is 94 // if the List is a builtin VM List type and false if it is
93 // a user defined List type. 95 // a user defined List type.
94 external static bool _isBuiltinList(List buffer); 96 external static bool _isBuiltinList(List buffer);
95 } 97 }
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698