QProcessPrivate: repack and reorganize the members

Reduce the number of #ifdef blocks and use quint8 for the enums that
don't need more than 8 bits anyway (none of them do). Plus move the
std::function callback to an indirect block, as most users of QProcess
won't set them and this type is 4 pointers with libstdc++ and libc++.

After this, QProcessPrivate on 64-bit Unix is 688 bytes, of which:
- 392 bytes from QIODevicePrivate
- 295 bytes of own data
- 3x56 bytes per Channel (which have 5 bytes of tail padding each)
- 1 byte of tail padding and no middle padding

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d188a0821d060
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Thiago Macieira 2023-03-16 20:53:37 -07:00 committed by Volker Hilsheimer
parent 7dba2c8761
commit 2b98dd7645
3 changed files with 36 additions and 38 deletions

View File

@ -922,7 +922,7 @@ void QProcessPrivate::setErrorAndEmit(QProcess::ProcessError error, const QStrin
Q_Q(QProcess);
Q_ASSERT(error != QProcess::UnknownError);
setError(error, description);
emit q->errorOccurred(processError);
emit q->errorOccurred(QProcess::ProcessError(processError));
}
/*!
@ -1154,7 +1154,7 @@ void QProcessPrivate::processFinished()
//emit q->standardOutputClosed();
//emit q->standardErrorClosed();
emit q->finished(exitCode, exitStatus);
emit q->finished(exitCode, QProcess::ExitStatus(exitStatus));
#if defined QPROCESS_DEBUG
qDebug("QProcessPrivate::processFinished(): process is dead");
@ -1239,7 +1239,7 @@ QProcess::~QProcess()
QProcess::ProcessChannelMode QProcess::processChannelMode() const
{
Q_D(const QProcess);
return d->processChannelMode;
return ProcessChannelMode(d->processChannelMode);
}
/*!
@ -1269,7 +1269,7 @@ void QProcess::setProcessChannelMode(ProcessChannelMode mode)
QProcess::InputChannelMode QProcess::inputChannelMode() const
{
Q_D(const QProcess);
return d->inputChannelMode;
return InputChannelMode(d->inputChannelMode);
}
/*!
@ -1558,7 +1558,7 @@ void QProcess::setCreateProcessArgumentsModifier(CreateProcessArgumentModifier m
std::function<void(void)> QProcess::childProcessModifier() const
{
Q_D(const QProcess);
return d->childProcessModifier;
return d->unixExtras ? d->unixExtras->childProcessModifier : std::function<void(void)>();
}
/*!
@ -1602,7 +1602,9 @@ std::function<void(void)> QProcess::childProcessModifier() const
void QProcess::setChildProcessModifier(const std::function<void(void)> &modifier)
{
Q_D(QProcess);
d->childProcessModifier = modifier;
if (!d->unixExtras)
d->unixExtras.reset(new QProcessPrivate::UnixExtras);
d->unixExtras->childProcessModifier = modifier;
}
#endif
@ -1693,7 +1695,7 @@ qint64 QProcess::bytesToWrite() const
QProcess::ProcessError QProcess::error() const
{
Q_D(const QProcess);
return d->processError;
return ProcessError(d->processError);
}
/*!
@ -1704,7 +1706,7 @@ QProcess::ProcessError QProcess::error() const
QProcess::ProcessState QProcess::state() const
{
Q_D(const QProcess);
return d->processState;
return ProcessState(d->processState);
}
/*!
@ -2373,7 +2375,7 @@ int QProcess::exitCode() const
QProcess::ExitStatus QProcess::exitStatus() const
{
Q_D(const QProcess);
return d->exitStatus;
return ExitStatus(d->exitStatus);
}
/*!

View File

@ -259,20 +259,6 @@ public:
bool _q_startupNotification();
void _q_processDied();
QProcess::ProcessChannelMode processChannelMode = QProcess::SeparateChannels;
QProcess::InputChannelMode inputChannelMode = QProcess::ManagedInputChannel;
QProcess::ProcessError processError = QProcess::UnknownError;
QProcess::ProcessState processState = QProcess::NotRunning;
QString workingDirectory;
#ifdef Q_OS_WIN
Q_PROCESS_INFORMATION *pid = nullptr;
#else
qint64 pid = 0;
#endif
bool emittedReadyRead = false;
bool emittedBytesWritten = false;
Channel stdinChannel;
Channel stdoutChannel;
Channel stderrChannel;
@ -286,22 +272,33 @@ public:
QString program;
QStringList arguments;
QString workingDirectory;
QProcessEnvironment environment = QProcessEnvironment::InheritFromParent;
#if defined(Q_OS_WIN)
QString nativeArguments;
QProcess::CreateProcessArgumentModifier modifyCreateProcessArgs;
#else
std::function<void(void)> childProcessModifier;
#endif
QProcessEnvironment environment = QProcessEnvironment::InheritFromParent;
#ifdef Q_OS_UNIX
Q_PIPE childStartedPipe[2] = {INVALID_Q_PIPE, INVALID_Q_PIPE};
QSocketNotifier *stateNotifier = nullptr;
int forkfd = -1;
#else
QWinEventNotifier *processFinishedNotifier = nullptr;
Q_PROCESS_INFORMATION *pid = nullptr;
#else
struct UnixExtras {
std::function<void(void)> childProcessModifier;
};
std::unique_ptr<UnixExtras> unixExtras;
qint64 pid = 0;
QSocketNotifier *stateNotifier = nullptr;
Q_PIPE childStartedPipe[2] = {INVALID_Q_PIPE, INVALID_Q_PIPE};
int forkfd = -1;
#endif
int exitCode = 0;
quint8 processState = QProcess::NotRunning;
quint8 exitStatus = QProcess::NormalExit;
quint8 processError = QProcess::UnknownError;
quint8 processChannelMode = QProcess::SeparateChannels;
quint8 inputChannelMode = QProcess::ManagedInputChannel;
bool emittedReadyRead = false;
bool emittedBytesWritten = false;
void start(QIODevice::OpenMode mode);
void startProcess();
#if defined(Q_OS_UNIX)
@ -325,9 +322,6 @@ public:
bool startDetached(qint64 *pPid);
int exitCode = 0;
QProcess::ExitStatus exitStatus = QProcess::NormalExit;
bool waitForStarted(const QDeadlineTimer &deadline);
bool waitForReadyRead(const QDeadlineTimer &deadline);
bool waitForBytesWritten(const QDeadlineTimer &deadline);

View File

@ -544,8 +544,10 @@ void QProcessPrivate::execChild(const char *workingDir, char **argv, char **envp
goto report_errno;
}
if (childProcessModifier)
childProcessModifier();
if (unixExtras) {
if (unixExtras->childProcessModifier)
unixExtras->childProcessModifier();
}
// execute the process
if (!envp) {