QByteArray::setNum: use assign() instead of clear()+append()
clear() will shed any stored capacity, so that's a waste for the few people who actually use setNum(). The majority use it from number(), in which case the clear() is superfluous anyway. And append() does an extra strlen() check, which we don't need. This considerably reduces the size of both QByteArray::setNum() in a GCC LTO build (though the compiler chose to not inline assign()). Moreover, it now does inline setNum() in the number() functions and in a lot more places (searching for "qulltoa2" in the disassembly finds it in QFileSystemEngine::id, for example). Change-Id: If3345151ddf84c43a4f1fffd17d28f2fc79aa072 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
6c7738a7d6
commit
56568fdee6
@ -4209,9 +4209,7 @@ QByteArray &QByteArray::setNum(qlonglong n, int base)
|
||||
p = qulltoa2(buff + buffsize, qulonglong(n), base);
|
||||
}
|
||||
|
||||
clear();
|
||||
append(p, buffsize - (p - buff));
|
||||
return *this;
|
||||
return assign(QByteArrayView{p, buff + buffsize});
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -4226,9 +4224,7 @@ QByteArray &QByteArray::setNum(qulonglong n, int base)
|
||||
char buff[buffsize];
|
||||
char *p = qulltoa2(buff + buffsize, n, base);
|
||||
|
||||
clear();
|
||||
append(p, buffsize - (p - buff));
|
||||
return *this;
|
||||
return assign(QByteArrayView{p, buff + buffsize});
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
x
Reference in New Issue
Block a user