Index: sdk/lib/io/common.dart |
diff --git a/sdk/lib/io/common.dart b/sdk/lib/io/common.dart |
index 31ce72b6c9232096c18104b1a907dc6bc4204972..ba5f07d9908b39f1ef811a97624ec53c3b1ac38d 100644 |
--- a/sdk/lib/io/common.dart |
+++ b/sdk/lib/io/common.dart |
@@ -100,7 +100,7 @@ class _BufferAndStart { |
// Only builtin Lists can be serialized through. If user-defined Lists |
// get here, the contents is copied to a Uint8List. This has the added |
// benefit that it is faster to access from the C code as well. |
-_BufferAndStart _ensureFastAndSerializableBuffer( |
+_BufferAndStart _ensureFastAndSerializableData( |
List buffer, int start, int end) { |
if (buffer is Uint8List || |
buffer is Int8List || |
@@ -131,6 +131,28 @@ _BufferAndStart _ensureFastAndSerializableBuffer( |
} |
+_BufferAndStart _ensureFastAndSerializableByteData( |
+ List buffer, int start, int end) { |
+ if (buffer is Uint8List) { |
+ return new _BufferAndStart(buffer, start); |
+ } |
+ int length = end - start; |
+ var newBuffer = new Uint8List(length); |
+ int j = start; |
+ for (int i = 0; i < length; i++) { |
+ int value = buffer[j]; |
+ if (value is! int || |
+ value < 0 || 255 < value) { |
+ throw new ArgumentError( |
+ "List element is not a byte value (value $value at index $j)"); |
+ } |
+ newBuffer[i] = value; |
+ j++; |
+ } |
+ return new _BufferAndStart(newBuffer, 0); |
+} |
+ |
+ |
// TODO(ager): The only reason for the class here is that |
// we cannot patch a top-level function. |
class _BufferUtils { |