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

Unified Diff: runtime/bin/socket.cc

Issue 11275074: Send data in an external byte array directly from the backing store (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase again Created 8 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket.cc
diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
index 3cde519941a22dc92f9f1debbfc3a7f8099c686c..8f8d4c99af18989b8aa9fb00d65ccc1a3cdd2fc1 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -176,28 +176,38 @@ void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
length = (length + 1) / 2;
}
- // Send data in chunks of maximum 16KB.
- const intptr_t max_chunk_length =
- dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB));
- uint8_t* buffer = new uint8_t[max_chunk_length];
intptr_t total_bytes_written = 0;
intptr_t bytes_written = 0;
- do {
- intptr_t chunk_length =
- dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
- result = Dart_ListGetAsBytes(buffer_obj,
- offset + total_bytes_written,
- buffer,
- chunk_length);
+ if (Dart_IsByteArrayExternal(buffer_obj)) {
+ void* buffer = NULL;
+ result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer);
if (Dart_IsError(result)) {
- delete[] buffer;
Dart_PropagateError(result);
}
- bytes_written =
- Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length);
- total_bytes_written += bytes_written;
- } while (bytes_written > 0 && total_bytes_written < length);
- delete[] buffer;
+ bytes_written = Socket::Write(socket, buffer, length);
+ total_bytes_written = bytes_written;
+ } else {
+ // Send data in chunks of maximum 16KB.
+ const intptr_t max_chunk_length =
+ dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB));
+ uint8_t* buffer = new uint8_t[max_chunk_length];
+ do {
+ intptr_t chunk_length =
+ dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
+ result = Dart_ListGetAsBytes(buffer_obj,
+ offset + total_bytes_written,
+ buffer,
+ chunk_length);
+ if (Dart_IsError(result)) {
+ delete[] buffer;
+ Dart_PropagateError(result);
+ }
+ bytes_written =
+ Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length);
+ total_bytes_written += bytes_written;
+ } while (bytes_written > 0 && total_bytes_written < length);
+ delete[] buffer;
+ }
if (bytes_written >= 0) {
Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written));
} else {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698