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

Unified Diff: runtime/bin/vmservice/server.dart

Issue 2254543006: Reduce copying in sending service responses. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: dbc, sync Created 4 years, 4 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 | « no previous file | runtime/bin/vmservice/vmservice_io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/server.dart
diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart
index 4075e8d427886d363b4b9c31aabeba5ad5c1c7be..c032c2613f95e15bae71b5f625a29c0281e0f530 100644
--- a/runtime/bin/vmservice/server.dart
+++ b/runtime/bin/vmservice/server.dart
@@ -51,7 +51,17 @@ class WebSocketClient extends Client {
return;
}
try {
- socket.add(result);
+ if (result is String || result is Uint8List) {
+ socket.add(result); // String or binary message.
+ } else {
+ // String message as external Uint8List.
+ assert(result is List);
+ Uint8List cstring = result[0];
+ // TODO(rmacnak): cstring may be large. Add a way to pass an encoded
+ // string to a web socket that will be sent as a text message to avoid
+ // the space overhead of converting cstring to a Dart string.
+ socket.add(UTF8.decode(cstring));
+ }
} catch (_) {
print("Ignoring error posting over WebSocket.");
}
@@ -79,14 +89,21 @@ class HttpRequestClient extends Client {
close();
}
- void post(String result) {
+ void post(dynamic result) {
if (result == null) {
close();
return;
}
- request.response..headers.contentType = jsonContentType
- ..write(result)
- ..close();
+ HttpResponse response = request.response;
+ response.headers.contentType = jsonContentType;
+ if (result is String) {
+ response.write(result);
+ } else {
+ assert(result is List);
+ Uint8List cstring = result[0]; // Already in UTF-8.
+ response.add(cstring);
+ }
+ response.close();
close();
}
« no previous file with comments | « no previous file | runtime/bin/vmservice/vmservice_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698