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

Side by Side Diff: runtime/bin/file_impl.dart

Issue 9254022: Make sure to use an ObjectArray when writing to a socket (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Really address the review comments from ager@ Created 8 years, 11 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/bin/socket_impl.dart » ('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) 2011, 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 class _FileInputStream extends _BaseDataInputStream implements InputStream { 5 class _FileInputStream extends _BaseDataInputStream implements InputStream {
6 _FileInputStream(File file) { 6 _FileInputStream(File file) {
7 _file = file.openSync(); 7 _file = file.openSync();
8 _length = _file.lengthSync(); 8 _length = _file.lengthSync();
9 _streamMarkedClosed = true; 9 _streamMarkedClosed = true;
10 _checkScheduleCallbacks(); 10 _checkScheduleCallbacks();
11 } 11 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 _replyPort.send(0, port.toSendPort()); 214 _replyPort.send(0, port.toSendPort());
215 return; 215 return;
216 } 216 }
217 int index = 217 int index =
218 _FileUtils.checkReadWriteListArguments(_buffer.length, _offset, _bytes); 218 _FileUtils.checkReadWriteListArguments(_buffer.length, _offset, _bytes);
219 if (index != 0) { 219 if (index != 0) {
220 _replyPort.send("index out of range in writeList: $index", 220 _replyPort.send("index out of range in writeList: $index",
221 port.toSendPort()); 221 port.toSendPort());
222 return; 222 return;
223 } 223 }
224 var result = _FileUtils._writeList(_id, _buffer, _offset, _bytes); 224 var result = _FileUtils.writeList(_id, _buffer, _offset, _bytes);
225 _replyPort.send(result, port.toSendPort()); 225 _replyPort.send(result, port.toSendPort());
226 } 226 }
227 227
228 bool isWrite() => true; 228 bool isWrite() => true;
229 229
230 int _id; 230 int _id;
231 List _buffer; 231 List _buffer;
232 int _offset; 232 int _offset;
233 int _bytes; 233 int _bytes;
234 } 234 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 static bool exists(String name) native "File_Exists"; 413 static bool exists(String name) native "File_Exists";
414 static int open(String name, int mode) native "File_Open"; 414 static int open(String name, int mode) native "File_Open";
415 static bool create(String name) native "File_Create"; 415 static bool create(String name) native "File_Create";
416 static bool delete(String name) native "File_Delete"; 416 static bool delete(String name) native "File_Delete";
417 static String fullPath(String name) native "File_FullPath"; 417 static String fullPath(String name) native "File_FullPath";
418 static int close(int id) native "File_Close"; 418 static int close(int id) native "File_Close";
419 static int readByte(int id) native "File_ReadByte"; 419 static int readByte(int id) native "File_ReadByte";
420 static int readList(int id, List<int> buffer, int offset, int bytes) 420 static int readList(int id, List<int> buffer, int offset, int bytes)
421 native "File_ReadList"; 421 native "File_ReadList";
422 static int writeByte(int id, int value) native "File_WriteByte"; 422 static int writeByte(int id, int value) native "File_WriteByte";
423 static int _writeList(int id, List<int> buffer, int offset, int bytes) { 423 static int writeList(int id, List<int> buffer, int offset, int bytes) {
424 ObjectArray out_buffer; 424 // When using the Dart C API access to ObjectArray by index is
425 int out_offset = offset; 425 // currently much faster. This function will make a copy of the
426 // supplied List to an ObjectArray if it isn't already.
427 ObjectArray outBuffer;
428 int outOffset = offset;
426 if (buffer is ObjectArray) { 429 if (buffer is ObjectArray) {
427 out_buffer = buffer; 430 outBuffer = buffer;
428 } else { 431 } else {
429 out_buffer = new ObjectArray(bytes); 432 outBuffer = new ObjectArray(bytes);
430 out_offset = 0; 433 outOffset = 0;
431 int j = offset; 434 int j = offset;
432 for (int i = 0; i < bytes; i++) { 435 for (int i = 0; i < bytes; i++) {
433 out_buffer[i] = buffer[j]; 436 outBuffer[i] = buffer[j];
434 j++; 437 j++;
435 } 438 }
436 } 439 }
437 return __writeList(id, out_buffer, out_offset, bytes); 440 return writeListNative(id, outBuffer, outOffset, bytes);
438 } 441 }
439 static int __writeList(int id, List<int> buffer, int offset, int bytes) 442 static int writeListNative(int id, List<int> buffer, int offset, int bytes)
440 native "File_WriteList"; 443 native "File_WriteList";
441 static int writeString(int id, String string) native "File_WriteString"; 444 static int writeString(int id, String string) native "File_WriteString";
442 static int position(int id) native "File_Position"; 445 static int position(int id) native "File_Position";
443 static bool setPosition(int id, int position) native "File_SetPosition"; 446 static bool setPosition(int id, int position) native "File_SetPosition";
444 static bool truncate(int id, int length) native "File_Truncate"; 447 static bool truncate(int id, int length) native "File_Truncate";
445 static int length(int id) native "File_Length"; 448 static int length(int id) native "File_Length";
446 static int flush(int id) native "File_Flush"; 449 static int flush(int id) native "File_Flush";
447 450
448 static int checkedOpen(String name, int mode) { 451 static int checkedOpen(String name, int mode) {
449 if (name is !String || mode is !int) return 0; 452 if (name is !String || mode is !int) return 0;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 } 859 }
857 if (buffer is !List || offset is !int || bytes is !int) { 860 if (buffer is !List || offset is !int || bytes is !int) {
858 throw new FileIOException("Invalid arguments to writeList"); 861 throw new FileIOException("Invalid arguments to writeList");
859 } 862 }
860 if (bytes == 0) return 0; 863 if (bytes == 0) return 0;
861 int index = 864 int index =
862 _FileUtils.checkReadWriteListArguments(buffer.length, offset, bytes); 865 _FileUtils.checkReadWriteListArguments(buffer.length, offset, bytes);
863 if (index != 0) { 866 if (index != 0) {
864 throw new IndexOutOfRangeException(index); 867 throw new IndexOutOfRangeException(index);
865 } 868 }
866 int result = _FileUtils._writeList(_id, buffer, offset, bytes); 869 int result = _FileUtils.writeList(_id, buffer, offset, bytes);
867 if (result == -1) { 870 if (result == -1) {
868 throw new FileIOException("writeList failed"); 871 throw new FileIOException("writeList failed");
869 } 872 }
870 return result; 873 return result;
871 } 874 }
872 875
873 void writeString(String string) { 876 void writeString(String string) {
874 _asyncUsed = true; 877 _asyncUsed = true;
875 var handleWriteStringResult = (result, ignored) { 878 var handleWriteStringResult = (result, ignored) {
876 if (result == -1 &&_errorHandler != null) { 879 if (result == -1 &&_errorHandler != null) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 var _readByteHandler; 1082 var _readByteHandler;
1080 var _readListHandler; 1083 var _readListHandler;
1081 var _noPendingWriteHandler; 1084 var _noPendingWriteHandler;
1082 var _positionHandler; 1085 var _positionHandler;
1083 var _setPositionHandler; 1086 var _setPositionHandler;
1084 var _truncateHandler; 1087 var _truncateHandler;
1085 var _lengthHandler; 1088 var _lengthHandler;
1086 var _flushHandler; 1089 var _flushHandler;
1087 var _errorHandler; 1090 var _errorHandler;
1088 } 1091 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/socket_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698