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

Unified Diff: mojo/public/dart/mojo/lib/src/message_pipe.dart

Issue 1410053002: Dart: Uses a pre-allocated buffer for message pipe query and read. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 | « mojo/public/dart/mojo/lib/src/message.dart ('k') | mojo/public/dart/mojo/lib/src/proxy.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/dart/mojo/lib/src/message_pipe.dart
diff --git a/mojo/public/dart/mojo/lib/src/message_pipe.dart b/mojo/public/dart/mojo/lib/src/message_pipe.dart
index 68ed35bb8b22da9e398838b944d7b262b5061963..5841a3a6f5b8eb3c803db7e768c26085e77ec78e 100644
--- a/mojo/public/dart/mojo/lib/src/message_pipe.dart
+++ b/mojo/public/dart/mojo/lib/src/message_pipe.dart
@@ -19,25 +19,49 @@ class MojoMessagePipeReadResult {
}
}
-class MojoMessagePipeQueryAndReadResult {
- MojoResult status;
- ByteData bytesRead;
- List<MojoHandle> handlesRead;
-
- MojoMessagePipeQueryAndReadResult.fromList(List result) {
- status = new MojoResult(result[0]);
- bytesRead = result[1];
- if (result[2] != null) {
- handlesRead = new List<MojoHandle>(result[2].length);
- for (int i = 0; i < handlesRead.length; i++) {
- handlesRead[i] = new MojoHandle(result[2][i]);
+class MojoMessagePipeQueryAndReadState {
+ static ByteData _data;
+ static Uint32List _rawHandles;
+ static final List _result = new List(5);
+
+ MojoResult _status;
+ List<MojoHandle> _handles;
+ int _dataLength;
+ int _handlesLength;
+
+ MojoResult get status => _status;
+ List<MojoHandle> get handles => _handles;
+ int get dataLength => _dataLength;
+ int get handlesLength => _handlesLength;
+ ByteData get data => _data;
+
+ MojoMessagePipeQueryAndReadState()
+ : _dataLength = 0,
+ _handlesLength = 0;
+
+ void queryAndRead(int handle, int flags) {
+ MojoMessagePipeNatives.MojoQueryAndReadMessage(
+ handle, flags, _data, _rawHandles, _result);
+ _status = new MojoResult(_result[0]);
+ _data = _result[1];
+ _rawHandles = _result[2];
+ _dataLength = _result[3];
+ _handlesLength = _result[4];
+
+ if (_handlesLength == 0) {
+ _handles = null;
+ } else {
+ _handles = new List(_handlesLength);
+ for (int i = 0; i < _handlesLength; i++) {
+ _handles[i] = new MojoHandle(_rawHandles[i]);
}
}
}
String toString() {
- return "MojoMessagePipeQueryAndReadResult("
- "status: $status, bytesRead: $bytesRead, handlesRead: $handlesRead)";
+ return "MojoMessagePipeQueryAndReadState("
+ "status: $_status, dataLength: $dataLength, "
+ "handlesLength: $handlesLength)";
}
}
@@ -49,7 +73,10 @@ class MojoMessagePipeEndpoint {
MojoHandle handle;
MojoResult status;
- MojoMessagePipeEndpoint(this.handle);
+ MojoMessagePipeQueryAndReadState _queryAndReadState;
+
+ MojoMessagePipeEndpoint(this.handle)
+ : _queryAndReadState = new MojoMessagePipeQueryAndReadState();
MojoResult write(ByteData data,
[int numBytes = -1, List<MojoHandle> handles = null, int flags = 0]) {
@@ -131,24 +158,17 @@ class MojoMessagePipeEndpoint {
MojoMessagePipeReadResult query() => read(null);
- MojoMessagePipeQueryAndReadResult queryAndRead([int flags = 0]) {
+ // Warning: The object returned by this function, and the buffers inside of it
+ // are only valid until the next call to this function by the same isolate.
+ MojoMessagePipeQueryAndReadState queryAndRead([int flags = 0]) {
if (handle == null) {
status = MojoResult.INVALID_ARGUMENT;
return null;
}
- List result =
- MojoMessagePipeNatives.MojoQueryAndReadMessage(handle.h, flags);
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
- assert((result is List) && (result.length == 3));
-
- var readResult = new MojoMessagePipeQueryAndReadResult.fromList(result);
-
- status = readResult.status;
- return readResult;
+ _queryAndReadState.queryAndRead(handle.h, flags);
+ status = _queryAndReadState.status;
+ return _queryAndReadState;
}
bool setDescription(String description) {
« no previous file with comments | « mojo/public/dart/mojo/lib/src/message.dart ('k') | mojo/public/dart/mojo/lib/src/proxy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698