Skip to content

Commit 08ce630

Browse files
authored
chore: Optimize the use of deepcopy in Translator._get_function_names() (#2765)
1 parent 2f53aeb commit 08ce630

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

samtranslator/translator/translator.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ def _get_function_names(
7474
if item.get("Type") == "Api" and item_properties.get("RestApiId"):
7575
rest_api = item_properties.get("RestApiId")
7676
api_name = Api.get_rest_api_id_string(rest_api)
77-
if isinstance(api_name, str):
78-
resource_dict_copy = copy.deepcopy(resource_dict)
79-
function_name = intrinsics_resolver.resolve_parameter_refs(
80-
resource_dict_copy.get("Properties", {}).get("FunctionName")
81-
)
82-
if function_name:
83-
self.function_names[api_name] = str(self.function_names.get(api_name, "")) + str(
84-
function_name
85-
)
77+
if not isinstance(api_name, str):
78+
continue
79+
raw_function_name = resource_dict.get("Properties", {}).get("FunctionName")
80+
resolved_function_name = intrinsics_resolver.resolve_parameter_refs(
81+
copy.deepcopy(raw_function_name)
82+
)
83+
if not resolved_function_name:
84+
continue
85+
self.function_names.setdefault(api_name, "")
86+
self.function_names[api_name] += str(resolved_function_name)
8687
return self.function_names
8788

8889
def translate(

0 commit comments

Comments
 (0)