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

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

Issue 1415253008: Dart: Merge message pipe query and read into one native call (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: add cast Created 5 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
Index: mojo/public/dart/mojo/lib/src/codec.dart
diff --git a/mojo/public/dart/mojo/lib/src/codec.dart b/mojo/public/dart/mojo/lib/src/codec.dart
index 020312b152b1590290221aebadd2ccf42d79364f..0332ef3a3a53e59fcc40f8c0ef510ee056ef997a 100644
--- a/mojo/public/dart/mojo/lib/src/codec.dart
+++ b/mojo/public/dart/mojo/lib/src/codec.dart
@@ -105,7 +105,8 @@ class Encoder {
return result;
}
- Message get message => new Message(_buffer.trimmed, _buffer.handles);
+ Message get message => new Message(
+ _buffer.trimmed, _buffer.handles, _buffer.extent, _buffer.handles.length);
void encodeStructDataHeader(StructDataHeader dataHeader) {
_buffer.claimMemory(align(dataHeader.size));
@@ -561,8 +562,7 @@ class Decoder {
Decoder(this._message, [this._base = 0, this._validator = null]) {
if (_validator == null) {
- _validator = new _Validator(
- _message.buffer.lengthInBytes, _message.handles.length);
+ _validator = new _Validator(_message.dataLength, _message.handlesLength);
}
}
@@ -574,9 +574,13 @@ class Decoder {
ByteData get _buffer => _message.buffer;
List<core.MojoHandle> get _handles => _message.handles;
- List<core.MojoHandle> get excessHandles => new List.from(_message.handles
- .getRange(_validator._minNextClaimedHandle, _message.handles.length))
- ..addAll(_validator._skippedIndices.map((i) => _message.handles[i]));
+ List<core.MojoHandle> get excessHandles {
+ if (_message.handlesLength == 0) return null;
+ var leftAtEnd = _message.handles
+ .getRange(_validator._minNextClaimedHandle, _message.handlesLength);
+ var skipped = _validator._skippedIndices.map((i) => _message.handles[i]);
+ return new List.from(leftAtEnd)..addAll(skipped);
+ }
int decodeInt8(int offset) => _buffer.getInt8(_base + offset);
int decodeUint8(int offset) => _buffer.getUint8(_base + offset);
@@ -760,7 +764,7 @@ class Decoder {
var header = d.decodeDataHeaderForArray(elementSize, expectedLength);
return arrayViewer(d._buffer.buffer,
d._buffer.offsetInBytes + d._base + ArrayDataHeader.kHeaderSize,
- header.numElements);
+ header.numElements).toList();
}
List<int> decodeInt8Array(int offset, int nullability, int expectedLength) =>
@@ -860,16 +864,13 @@ class Decoder {
(d, o, n) => d.decodeServiceInterface(o, n, clientFactory), offset,
kSerializedInterfaceSize, nullability, expectedLength);
- static String _stringOfUtf8(Uint8List bytes) =>
- (const Utf8Decoder()).convert(bytes.toList());
-
String decodeString(int offset, bool nullable) {
int nullability = nullable ? kArrayNullable : 0;
var bytes = decodeUint8Array(offset, nullability, kUnspecifiedArrayLength);
if (bytes == null) {
return null;
}
- return _stringOfUtf8(bytes);
+ return (const Utf8Decoder()).convert(bytes);
}
StructDataHeader decodeDataHeaderForMap() {
« no previous file with comments | « no previous file | mojo/public/dart/mojo/lib/src/message.dart » ('j') | mojo/public/dart/mojo/lib/src/message_pipe.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698