address review comments
diff --git a/lib/src/body.dart b/lib/src/body.dart
index 8501564..dbd3873 100644
--- a/lib/src/body.dart
+++ b/lib/src/body.dart
@@ -53,15 +53,12 @@
stream = Stream.fromIterable([encoded]);
}
} else if (body is List<int>) {
- // Any data that is written to a Dart socket that is not a Uint8List or
- // Int8List must be copied into a new list. Allow users to provide a
- // typed data object to avoid this copy, which is important for performance
- // of large file requests.
+ // Avoid performance overhead from an unnecessary cast.
contentLength = body.length;
- stream = Stream.fromIterable([body]);
+ stream = Stream.value(body);
} else if (body is List) {
contentLength = body.length;
- stream = Stream.fromIterable([body.cast()]);
+ stream = Stream.value(body.cast());
} else if (body is Stream) {
stream = body.cast();
} else {
diff --git a/test/response_test.dart b/test/response_test.dart
index 92d45dd..794ed67 100644
--- a/test/response_test.dart
+++ b/test/response_test.dart
@@ -31,7 +31,7 @@
var response = Response.ok(bytes);
expect(response.contentLength, 10);
- expect(identical(await response.read().first, bytes), true);
+ expect(await response.read().single, same(bytes));
});
test('supports a List<int> body without copying', () async {
@@ -39,7 +39,7 @@
var response = Response.ok(bytes);
expect(response.contentLength, 4);
- expect(identical(await response.read().first, bytes), true);
+ expect(await response.read().single, same(bytes));
});
test('Copies a dynamic list of int elements', () async {
@@ -47,7 +47,10 @@
var response = Response.ok(bytes);
expect(response.contentLength, 4);
- expect(await response.read().first, <int>[1, 2, 3, 4]);
+ expect(
+ await response.read().single,
+ isA<List<int>>()
+ .having((List<int> values) => values, 'values', [1, 2, 3, 4]));
});
group('new Response.internalServerError without a body', () {