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

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

Issue 14018007: Rename RandomAccessFile.readList and RandomAccessFile.writeList to RandomAccessFile.readInto and Ra… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix return type. Created 7 years, 8 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 part of dart.io; 5 part of dart.io;
6 6
7 // Constants used when working with native ports. 7 // Constants used when working with native ports.
8 const int _SUCCESS_RESPONSE = 0; 8 const int _SUCCESS_RESPONSE = 0;
9 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; 9 const int _ILLEGAL_ARGUMENT_RESPONSE = 1;
10 const int _OSERROR_RESPONSE = 2; 10 const int _OSERROR_RESPONSE = 2;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 /** 52 /**
53 * Error code supplied by the operating system. Will have the value 53 * Error code supplied by the operating system. Will have the value
54 * [noErrorCode] if there is no error code associated with the error. 54 * [noErrorCode] if there is no error code associated with the error.
55 */ 55 */
56 final int errorCode; 56 final int errorCode;
57 } 57 }
58 58
59 59
60 // Object for holding a buffer and an offset. 60 // Object for holding a buffer and an offset.
61 class _BufferAndOffset { 61 class _BufferAndStart {
62 _BufferAndOffset(List this.buffer, int this.offset); 62 _BufferAndStart(List this.buffer, int this.start);
63 List buffer; 63 List buffer;
64 int offset; 64 int start;
65 } 65 }
66 66
67 // Ensure that the input List can be serialized through a native port. 67 // Ensure that the input List can be serialized through a native port.
68 // Only builtin Lists can be serialized through. If user-defined Lists 68 // Only builtin Lists can be serialized through. If user-defined Lists
69 // get here, the contents is copied to a Uint8List. This has the added 69 // get here, the contents is copied to a Uint8List. This has the added
70 // benefit that it is faster to access from the C code as well. 70 // benefit that it is faster to access from the C code as well.
71 _BufferAndOffset _ensureFastAndSerializableBuffer( 71 _BufferAndStart _ensureFastAndSerializableBuffer(
72 List buffer, int offset, int bytes) { 72 List buffer, int start, int end) {
73 if (buffer is Uint8List || 73 if (buffer is Uint8List ||
74 buffer is Int8List || 74 buffer is Int8List ||
75 buffer is Uint16List || 75 buffer is Uint16List ||
76 buffer is Int16List || 76 buffer is Int16List ||
77 _BufferUtils._isBuiltinList(buffer)) { 77 _BufferUtils._isBuiltinList(buffer)) {
78 return new _BufferAndOffset(buffer, offset); 78 return new _BufferAndStart(buffer, start);
79 } 79 }
80 var newBuffer = new Uint8List(bytes); 80 int length = end - start;
81 int j = offset; 81 var newBuffer = new Uint8List(length);
82 for (int i = 0; i < bytes; i++) { 82 int j = start;
83 for (int i = 0; i < length; i++) {
83 int value = buffer[j]; 84 int value = buffer[j];
84 if (value is! int) { 85 if (value is! int) {
85 throw new ArgumentError("List element is not an integer at index $j"); 86 throw new ArgumentError("List element is not an integer at index $j");
86 } 87 }
87 newBuffer[i] = value; 88 newBuffer[i] = value;
88 j++; 89 j++;
89 } 90 }
90 return new _BufferAndOffset(newBuffer, 0); 91 return new _BufferAndStart(newBuffer, 0);
91 } 92 }
92 93
93 94
94 // TODO(ager): The only reason for the class here is that 95 // TODO(ager): The only reason for the class here is that
95 // we cannot patch a top-level function. 96 // we cannot patch a top-level function.
96 class _BufferUtils { 97 class _BufferUtils {
97 // Check if a List is a builtin VM List type. Returns true 98 // Check if a List is a builtin VM List type. Returns true
98 // if the List is a builtin VM List type and false if it is 99 // if the List is a builtin VM List type and false if it is
99 // a user defined List type. 100 // a user defined List type.
100 external static bool _isBuiltinList(List buffer); 101 external static bool _isBuiltinList(List buffer);
101 } 102 }
102 103
103 class _IOCrypto { 104 class _IOCrypto {
104 external static Uint8List getRandomBytes(int count); 105 external static Uint8List getRandomBytes(int count);
105 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698