Optimized Query.clone() a bit.

This removes unnecessary "if ... is None" branches, which are already
shallow-copied in the __dict__.copy() call.
This commit is contained in:
Adam Johnson 2021-09-17 07:08:55 +02:00 committed by Mariusz Felisiak
parent f1bcaa9be8
commit 2931d847c2
1 changed files with 3 additions and 9 deletions

View File

@ -303,9 +303,7 @@ class Query(BaseExpression):
obj.table_map = self.table_map.copy() obj.table_map = self.table_map.copy()
obj.where = self.where.clone() obj.where = self.where.clone()
obj.annotations = self.annotations.copy() obj.annotations = self.annotations.copy()
if self.annotation_select_mask is None: if self.annotation_select_mask is not None:
obj.annotation_select_mask = None
else:
obj.annotation_select_mask = self.annotation_select_mask.copy() obj.annotation_select_mask = self.annotation_select_mask.copy()
obj.combined_queries = tuple(query.clone() for query in self.combined_queries) obj.combined_queries = tuple(query.clone() for query in self.combined_queries)
# _annotation_select_cache cannot be copied, as doing so breaks the # _annotation_select_cache cannot be copied, as doing so breaks the
@ -315,13 +313,9 @@ class Query(BaseExpression):
# used. # used.
obj._annotation_select_cache = None obj._annotation_select_cache = None
obj.extra = self.extra.copy() obj.extra = self.extra.copy()
if self.extra_select_mask is None: if self.extra_select_mask is not None:
obj.extra_select_mask = None
else:
obj.extra_select_mask = self.extra_select_mask.copy() obj.extra_select_mask = self.extra_select_mask.copy()
if self._extra_select_cache is None: if self._extra_select_cache is not None:
obj._extra_select_cache = None
else:
obj._extra_select_cache = self._extra_select_cache.copy() obj._extra_select_cache = self._extra_select_cache.copy()
if self.select_related is not False: if self.select_related is not False:
# Use deepcopy because select_related stores fields in nested # Use deepcopy because select_related stores fields in nested