Chromium Code Reviews| Index: runtime/bin/file_impl.dart |
| =================================================================== |
| --- runtime/bin/file_impl.dart (revision 3706) |
| +++ runtime/bin/file_impl.dart (working copy) |
| @@ -19,11 +19,11 @@ |
| } |
| List<int> _read(int bytesToRead) { |
| - List<int> result = new List<int>(bytesToRead); |
| + ByteArray result = new ByteArray(bytesToRead); |
| int bytesRead = _file.readListSync(result, 0, bytesToRead); |
| if (bytesRead < bytesToRead) { |
| - List<int> buffer = new List<int>(bytesRead); |
| - buffer.copyFrom(result, 0, 0, bytesRead); |
| + ByteArray buffer = new ByteArray(bytesRead); |
| + buffer.setRange(0, bytesRead, result); |
| result = buffer; |
| } |
| _checkScheduleCallbacks(); |
| @@ -175,7 +175,7 @@ |
| port.toSendPort()); |
| return; |
| } |
| - var buffer = new List(_bytes); |
| + ByteArray buffer = new ByteArray(_bytes); |
| var result = |
| new _ReadListResult(_FileUtils.readList(_id, buffer, 0, _bytes), |
| buffer); |
| @@ -421,19 +421,24 @@ |
| native "File_ReadList"; |
| static int writeByte(int id, int value) native "File_WriteByte"; |
| static int writeList(int id, List<int> buffer, int offset, int bytes) { |
| - // When using the Dart C API access to ObjectArray by index is |
| + // When using the Dart C API to access raw data, using ByteArray is |
| // currently much faster. This function will make a copy of the |
| - // supplied List to an ObjectArray if it isn't already. |
| - ObjectArray outBuffer; |
| + // supplied List to a ByteArray if it isn't already. |
| + ByteArray outBuffer; |
| int outOffset = offset; |
| - if (buffer is ObjectArray) { |
| + if (buffer is ByteArray) { |
| outBuffer = buffer; |
| } else { |
|
Ivan Posva
2012/02/01 01:12:41
How about not copying ObjectArrays either? They do
Anders Johnsen
2012/02/01 02:12:11
That was the initial idea, but Carl and I were thi
Ivan Posva
2012/02/01 20:01:34
I think all List implementations that are native t
Anders Johnsen
2012/02/01 20:20:41
Done.
|
| - outBuffer = new ObjectArray(bytes); |
| + outBuffer = new ByteArray(bytes); |
| outOffset = 0; |
| int j = offset; |
| for (int i = 0; i < bytes; i++) { |
| - outBuffer[i] = buffer[j]; |
| + try { |
| + outBuffer[i] = buffer[j]; |
| + } catch (IllegalArgumentException e) { |
| + throw const FileIOException( |
| + "List element is not an integer in byte range"); |
| + } |
| j++; |
| } |
| } |