optimize openModeToFopenMode() and openModeToOpenFlags() functions

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-10-19 23:54:16 +03:00
parent 8c1c4be290
commit 538dc6495c

View file

@ -61,7 +61,11 @@ static inline QByteArray openModeToFopenMode(QIODevice::OpenMode flags, const QF
QFileSystemMetaData &metaData)
{
QByteArray mode;
if ((flags & QIODevice::ReadOnly) && !(flags & QIODevice::Truncate)) {
if (flags & QIODevice::Append) {
mode = "ab";
if (flags & QIODevice::ReadOnly)
mode += '+';
} else if ((flags & QIODevice::ReadOnly) && !(flags & QIODevice::Truncate)) {
mode = "rb";
if (flags & QIODevice::WriteOnly) {
metaData.clearFlags(QFileSystemMetaData::FileType);
@ -78,11 +82,6 @@ static inline QByteArray openModeToFopenMode(QIODevice::OpenMode flags, const QF
if (flags & QIODevice::ReadOnly)
mode += '+';
}
if (flags & QIODevice::Append) {
mode = "ab";
if (flags & QIODevice::ReadOnly)
mode += '+';
}
#if defined(__GLIBC__)
// must be glibc >= 2.7
@ -99,9 +98,10 @@ static inline QByteArray openModeToFopenMode(QIODevice::OpenMode flags, const QF
*/
static inline int openModeToOpenFlags(QIODevice::OpenMode mode)
{
int oflags = QT_OPEN_RDONLY;
#ifdef QT_LARGEFILE_SUPPORT
oflags |= QT_OPEN_LARGEFILE;
int oflags = QT_OPEN_RDONLY | QT_OPEN_LARGEFILE;
#else
int oflags = QT_OPEN_RDONLY;
#endif
if ((mode & QFile::ReadWrite) == QFile::ReadWrite) {