QVarLengthArray: remove unneeded copy in replace()

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 <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2021-12-07 14:12:45 +01:00
parent ac4c0e1f02
commit adcc68fd59

View File

@ -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 <class T, qsizetype Prealloc>
inline void QVarLengthArray<T, Prealloc>::replace(qsizetype i, const T &t)
{
verify(i);
const T copy(t);
data()[i] = copy;
data()[i] = t;
}
template <class T, qsizetype Prealloc>