Skip to content

Commit 4e9cc05

Browse files
committed
copied over optimization for input proto
1 parent 3b4feff commit 4e9cc05

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,12 @@ class {{ service.async_client_name }}:
283283
request = {{ method.input.ident }}({% if method.input.ident.package != method.ident.package %}{% for f in method.flattened_fields.values() %}{{ f.name }}={{ f.name }}, {% endfor %}{% endif %})
284284
{% endif %}{# Cross-package req and flattened fields #}
285285
{% else %}
286-
request = {{ method.input.ident }}(request)
286+
# Minor optimization to avoid making a copy if the user passes
287+
# in a {{ method.input.ident }}.
288+
# There's no risk of modifying the input as we've already verified
289+
# there are no flattened fields.
290+
if not isinstance(request, {{ method.input.ident }}):
291+
request = {{ method.input.ident }}(request)
287292
{% endif %} {# different request package #}
288293

289294
{# Vanilla python protobuf wrapper types cannot _set_ repeated fields #}

0 commit comments

Comments
 (0)