mirror of https://github.com/grpc/grpc-dart.git
Use `Map.of` instead of `Map.from` in grpc client. (#724)
* Use `Map.of` instead of `Map.from` in grpc client. `Map.of` creates a new map with the same keys, values and *type* as the original map, when used without type arguments or context type, where `Map.from` creates a `Map<dynamic, dynamic>`. (This code failed on an attempt to make `Map.unmodifiable` be more strictly typed, like `Map.of` instead of `Map.from`, showing that an intermediate map had type `Map<dynamic, dynamic>` unnecessarily). Same for using `List.of` instead of `List.from`. The new code should be (microscopically) more efficient and type safe, and is forwards-compatible with a stronger type on `Map.unmodifiable`. (The code can be optimized more. For example `List.of(list1)..addAll(list2)` can be just `list1 + list2` or `[...list1, ...list2]`, both of which may know the total number of elements when doing the initial list allocation. This is a minimal change to allow the type changes for `.unmodifiable` to get past this very initial blocker in internal tests.) * Add changelog and minor version increment. And my save removes trailing spaces.
This commit is contained in:
parent
4f6fe9b111
commit
38ca626e0a
|
|
@ -1,3 +1,7 @@
|
||||||
|
## 4.0.2
|
||||||
|
|
||||||
|
* Internal optimization to client code.
|
||||||
|
|
||||||
## 4.0.1
|
## 4.0.1
|
||||||
|
|
||||||
* Fix header and trailing not completing if the call is terminated. Fixes [#727](https://github.com/grpc/grpc-dart/issues/727)
|
* Fix header and trailing not completing if the call is terminated. Fixes [#727](https://github.com/grpc/grpc-dart/issues/727)
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,9 @@ class CallOptions {
|
||||||
|
|
||||||
CallOptions mergedWith(CallOptions? other) {
|
CallOptions mergedWith(CallOptions? other) {
|
||||||
if (other == null) return this;
|
if (other == null) return this;
|
||||||
final mergedMetadata = Map.from(metadata)..addAll(other.metadata);
|
final mergedMetadata = Map.of(metadata)..addAll(other.metadata);
|
||||||
final mergedTimeout = other.timeout ?? timeout;
|
final mergedTimeout = other.timeout ?? timeout;
|
||||||
final mergedProviders = List.from(metadataProviders)
|
final mergedProviders = List.of(metadataProviders)
|
||||||
..addAll(other.metadataProviders);
|
..addAll(other.metadataProviders);
|
||||||
final mergedCompression = other.compression ?? compression;
|
final mergedCompression = other.compression ?? compression;
|
||||||
return CallOptions._(
|
return CallOptions._(
|
||||||
|
|
@ -146,9 +146,9 @@ class WebCallOptions extends CallOptions {
|
||||||
CallOptions mergedWith(CallOptions? other) {
|
CallOptions mergedWith(CallOptions? other) {
|
||||||
if (other == null) return this;
|
if (other == null) return this;
|
||||||
|
|
||||||
final mergedMetadata = Map.from(metadata)..addAll(other.metadata);
|
final mergedMetadata = Map.of(metadata)..addAll(other.metadata);
|
||||||
final mergedTimeout = other.timeout ?? timeout;
|
final mergedTimeout = other.timeout ?? timeout;
|
||||||
final mergedProviders = List.from(metadataProviders)
|
final mergedProviders = List.of(metadataProviders)
|
||||||
..addAll(other.metadataProviders);
|
..addAll(other.metadataProviders);
|
||||||
|
|
||||||
if (other is! WebCallOptions) {
|
if (other is! WebCallOptions) {
|
||||||
|
|
@ -241,7 +241,7 @@ class ClientCall<Q, R> implements Response {
|
||||||
if (options.metadataProviders.isEmpty) {
|
if (options.metadataProviders.isEmpty) {
|
||||||
_sendRequest(connection, _sanitizeMetadata(options.metadata));
|
_sendRequest(connection, _sanitizeMetadata(options.metadata));
|
||||||
} else {
|
} else {
|
||||||
final metadata = Map<String, String>.from(options.metadata);
|
final metadata = Map<String, String>.of(options.metadata);
|
||||||
Future.forEach(
|
Future.forEach(
|
||||||
options.metadataProviders,
|
options.metadataProviders,
|
||||||
(MetadataProvider provider) => provider(metadata,
|
(MetadataProvider provider) => provider(metadata,
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,7 @@ GrpcError? grpcErrorDetailsFromTrailers(Map<String, String> trailers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> toCustomTrailers(Map<String, String> trailers) {
|
Map<String, String> toCustomTrailers(Map<String, String> trailers) {
|
||||||
return Map.from(trailers)
|
return Map.of(trailers)
|
||||||
..remove(':status')
|
..remove(':status')
|
||||||
..remove('content-type')
|
..remove('content-type')
|
||||||
..remove('grpc-status')
|
..remove('grpc-status')
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
name: grpc
|
name: grpc
|
||||||
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework.
|
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework.
|
||||||
version: 4.0.1
|
version: 4.0.2
|
||||||
|
|
||||||
repository: https://github.com/grpc/grpc-dart
|
repository: https://github.com/grpc/grpc-dart
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue