From 2931d847c246b6f499993e370f6d9a53a83120d2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 17 Sep 2021 07:08:55 +0200 Subject: [PATCH] Optimized Query.clone() a bit. This removes unnecessary "if ... is None" branches, which are already shallow-copied in the __dict__.copy() call. --- django/db/models/sql/query.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 39a735b50e..433824044d 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -303,9 +303,7 @@ class Query(BaseExpression): obj.table_map = self.table_map.copy() obj.where = self.where.clone() obj.annotations = self.annotations.copy() - if self.annotation_select_mask is None: - obj.annotation_select_mask = None - else: + if self.annotation_select_mask is not None: obj.annotation_select_mask = self.annotation_select_mask.copy() obj.combined_queries = tuple(query.clone() for query in self.combined_queries) # _annotation_select_cache cannot be copied, as doing so breaks the @@ -315,13 +313,9 @@ class Query(BaseExpression): # used. obj._annotation_select_cache = None obj.extra = self.extra.copy() - if self.extra_select_mask is None: - obj.extra_select_mask = None - else: + if self.extra_select_mask is not None: obj.extra_select_mask = self.extra_select_mask.copy() - if self._extra_select_cache is None: - obj._extra_select_cache = None - else: + if self._extra_select_cache is not None: obj._extra_select_cache = self._extra_select_cache.copy() if self.select_related is not False: # Use deepcopy because select_related stores fields in nested