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

Unified Diff: runtime/bin/file_impl.dart

Issue 11000025: Revert hiding of VM-only coreimpl list implementation types. While I (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/common.dart ('k') | runtime/bin/process_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 2b08b7322eff1b439f33da130a561dcf02e7ba5e..145e4db197d8746f984d459fa2b03ddd78496ea8 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -335,6 +335,32 @@ class _FileUtils {
static const OSERROR_RESPONSE_ERROR_CODE = 1;
static const OSERROR_RESPONSE_MESSAGE = 2;
+ static List ensureFastAndSerializableBuffer(
+ List buffer, int offset, int bytes) {
+ // When using the Dart C API to access raw data, using a ByteArray is
+ // currently much faster. This function will make a copy of the
+ // supplied List to a ByteArray if it isn't already.
+ List outBuffer;
+ int outOffset = offset;
+ if (buffer is Uint8List || buffer is ObjectArray) {
+ outBuffer = buffer;
+ } else {
+ outBuffer = new Uint8List(bytes);
+ outOffset = 0;
+ int j = offset;
+ for (int i = 0; i < bytes; i++) {
+ int value = buffer[j];
+ if (value is! int) {
+ throw new FileIOException(
+ "List element is not an integer at index $j");
+ }
+ outBuffer[i] = value;
+ j++;
+ }
+ }
+ return [outBuffer, outOffset];
+ }
+
static exists(String name) native "File_Exists";
static open(String name, int mode) native "File_Open";
static create(String name) native "File_Create";
@@ -349,7 +375,8 @@ class _FileUtils {
native "File_ReadList";
static writeByte(int id, int value) native "File_WriteByte";
static writeList(int id, List<int> buffer, int offset, int bytes) {
- List result = _ensureFastAndSerializableBuffer(buffer, offset, bytes);
+ List result =
+ _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes);
List outBuffer = result[0];
int outOffset = result[1];
return writeListNative(id, outBuffer, outOffset, bytes);
@@ -919,7 +946,8 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
List result;
try {
- result = _ensureFastAndSerializableBuffer(buffer, offset, bytes);
+ result =
+ _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes);
} catch (e) {
// Complete asynchronously so the user has a chance to setup
// handlers without getting exceptions when registering the
« no previous file with comments | « runtime/bin/common.dart ('k') | runtime/bin/process_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698