From adcc68fd599d976dd79ad034b93e150138039681 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 7 Dec 2021 14:12:45 +0100 Subject: [PATCH] QVarLengthArray: remove unneeded copy in replace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QVarLengthArray is neither implicitly shared, nor does it feature a magic resize() on out-of-bounds. Therefore, data() doesn't detach(), so 't' remains stable. The only reason for the copy, then, would be if T wasn't self-assignment-safe, but we don't support such types. Remove the copy. Change-Id: I8dd12e1c9b8131ae17d641354fe362554062b78d Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a6e41168a83..2a86a1dd7f8 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -619,8 +619,7 @@ template inline void QVarLengthArray::replace(qsizetype i, const T &t) { verify(i); - const T copy(t); - data()[i] = copy; + data()[i] = t; } template