QtCore: include mocs

Compilation and link times in CPU seconds with GCC 7, using precompiled
headers (not including moc, rcc, uic, etc. steps or headersclean):

                Before  After
Debug -O0       198,1   180,3
Debug -Og       240,7   229,2
Release -O3     267,1   249,2
Release LTO     239,4   229,8

QtCore required a little manual adjusting because some files are
bootstrapped into moc itself and into qmake.

Change-Id: I84e363d735b443cb9beefffd14b8b57c10e7da36
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Thiago Macieira 2017-04-25 14:53:40 -03:00
parent f45c6c1804
commit 05f22d6eb2
45 changed files with 243 additions and 1 deletions

View File

@ -1484,5 +1484,6 @@ void QAbstractAnimation::updateDirection(QAbstractAnimation::Direction direction
QT_END_NAMESPACE
#include "moc_qabstractanimation.cpp"
#include "moc_qabstractanimation_p.cpp"
#endif //QT_NO_ANIMATION

View File

@ -1106,3 +1106,7 @@ qint64 QFile::size() const
}
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qfile.cpp"
#endif

View File

@ -739,3 +739,7 @@ bool QFileDevice::unmap(uchar *address)
}
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qfiledevice.cpp"
#endif

View File

@ -497,6 +497,7 @@ QStringList QFileSystemWatcher::files() const
QT_END_NAMESPACE
#include "moc_qfilesystemwatcher.cpp"
#include "moc_qfilesystemwatcher_p.cpp"
#endif // QT_NO_FILESYSTEMWATCHER

View File

@ -417,4 +417,6 @@ QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const
QT_END_NAMESPACE
#include "moc_qfilesystemwatcher_inotify_p.cpp"
#endif // QT_NO_FILESYSTEMWATCHER

View File

@ -151,4 +151,7 @@ void QPollingFileSystemWatcherEngine::timeout()
}
QT_END_NAMESPACE
#include "moc_qfilesystemwatcher_polling_p.cpp"
#endif // !QT_NO_FILESYSTEMWATCHER

View File

@ -2059,3 +2059,7 @@ QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)
#endif
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qiodevice.cpp"
#endif

View File

@ -578,3 +578,4 @@ QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteD
QT_END_NAMESPACE
#include "moc_qnoncontiguousbytedevice_p.cpp"

View File

@ -412,4 +412,8 @@ bool QSaveFile::directWriteFallback() const
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qsavefile.cpp"
#endif
#endif // QT_NO_TEMPORARYFILE

View File

@ -3513,4 +3513,8 @@ QSettings::Format QSettings::registerFormat(const QString &extension, ReadFunc r
QT_END_NAMESPACE
#ifndef QT_BOOTSTRAPPED
#include "moc_qsettings.cpp"
#endif
#endif // QT_NO_SETTINGS

View File

@ -645,4 +645,8 @@ bool QStandardPaths::isTestModeEnabled()
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qstandardpaths.cpp"
#endif
#endif // QT_NO_STANDARDPATHS

View File

@ -796,4 +796,6 @@ QT_END_NAMESPACE
#endif // QT_NO_TEMPORARYFILE
#ifndef QT_NO_QOBJECT
#include "moc_qtemporaryfile.cpp"
#endif

View File

@ -3188,3 +3188,6 @@ QLocale QTextStream::locale() const
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qtextstream_p.cpp"
#endif

View File

@ -3804,3 +3804,5 @@ void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex&
}
QT_END_NAMESPACE
#include "moc_qabstractitemmodel.cpp"

View File

@ -328,4 +328,6 @@ Qt::DropActions QStringListModel::supportedDropActions() const
QT_END_NAMESPACE
#include "moc_qstringlistmodel.cpp"
#endif // QT_NO_STRINGLISTMODEL

View File

@ -521,3 +521,5 @@ bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, vo
*/
QT_END_NAMESPACE
#include "moc_qabstracteventdispatcher.cpp"

View File

@ -2914,3 +2914,7 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
*/
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qcoreapplication.cpp"
#endif

View File

@ -652,3 +652,5 @@ QDeferredDeleteEvent::~QDeferredDeleteEvent()
*/
QT_END_NAMESPACE
#include "moc_qcoreevent.cpp"

View File

@ -611,3 +611,5 @@ QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObj
}
QT_END_NAMESPACE
#include "moc_qeventdispatcher_glib_p.cpp"

View File

@ -553,3 +553,5 @@ void QEventDispatcherUNIX::flush()
{ }
QT_END_NAMESPACE
#include "moc_qeventdispatcher_unix_p.cpp"

View File

@ -441,3 +441,5 @@ QEventLoopLocker::~QEventLoopLocker()
}
QT_END_NAMESPACE
#include "moc_qeventloop.cpp"

View File

@ -678,3 +678,5 @@ void QMimeData::removeFormat(const QString &mimeType)
}
QT_END_NAMESPACE
#include "moc_qmimedata.cpp"

View File

@ -145,3 +145,5 @@ void QObjectCleanupHandler::objectDestroyed(QObject *object)
}
QT_END_NAMESPACE
#include "moc_qobjectcleanuphandler.cpp"

View File

@ -598,3 +598,5 @@ QString QSharedMemory::errorString() const
#endif // QT_NO_SHAREDMEMORY
QT_END_NAMESPACE
#include "moc_qsharedmemory.cpp"

View File

@ -270,3 +270,5 @@ bool QSocketNotifier::event(QEvent *e)
}
QT_END_NAMESPACE
#include "moc_qsocketnotifier.cpp"

View File

@ -670,3 +670,4 @@ int QTimer::remainingTime() const
QT_END_NAMESPACE
#include "qtimer.moc"
#include "moc_qtimer.cpp"

View File

@ -1143,4 +1143,6 @@ bool QTranslator::isEmpty() const
QT_END_NAMESPACE
#include "moc_qtranslator.cpp"
#endif // QT_NO_TRANSLATION

View File

@ -346,4 +346,6 @@ int QFactoryLoader::indexOf(const QString &needle) const
QT_END_NAMESPACE
#include "moc_qfactoryloader_p.cpp"
#endif // QT_NO_QOBJECT

View File

@ -1129,3 +1129,5 @@ bool qt_debug_component()
}
QT_END_NAMESPACE
#include "moc_qlibrary.cpp"

View File

@ -479,3 +479,4 @@ QJsonObject QStaticPlugin::metaData() const
QT_END_NAMESPACE
#include "moc_qpluginloader.cpp"

View File

@ -234,3 +234,5 @@ bool QAbstractState::event(QEvent *e)
}
QT_END_NAMESPACE
#include "moc_qabstractstate.cpp"

View File

@ -431,3 +431,5 @@ bool QAbstractTransition::event(QEvent *e)
}
QT_END_NAMESPACE
#include "moc_qabstracttransition.cpp"

View File

@ -252,3 +252,5 @@ bool QEventTransition::event(QEvent *e)
}
QT_END_NAMESPACE
#include "moc_qeventtransition.cpp"

View File

@ -137,3 +137,5 @@ bool QFinalState::event(QEvent *e)
}
QT_END_NAMESPACE
#include "moc_qfinalstate.cpp"

View File

@ -310,3 +310,6 @@ bool QHistoryState::event(QEvent *e)
*/
QT_END_NAMESPACE
#include "moc_qhistorystate.cpp"
#include "moc_qhistorystate_p.cpp"

View File

@ -284,3 +284,5 @@ void QSignalTransitionPrivate::callOnTransition(QEvent *e)
QT_END_NAMESPACE
#include "moc_qsignaltransition.cpp"

View File

@ -599,3 +599,5 @@ bool QState::event(QEvent *e)
*/
QT_END_NAMESPACE
#include "moc_qstate.cpp"

View File

@ -592,4 +592,6 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event)
QT_END_NAMESPACE
#include "moc_qfuturewatcher.cpp"
#endif // QT_NO_QFUTURE

View File

@ -901,3 +901,5 @@ QDaemonThread::~QDaemonThread()
}
QT_END_NAMESPACE
#include "moc_qthread.cpp"

View File

@ -679,4 +679,6 @@ void QThreadPool::cancel(QRunnable *runnable)
QT_END_NAMESPACE
#include "moc_qthreadpool.cpp"
#endif

View File

@ -494,3 +494,7 @@ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method)
}
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qcryptographichash.cpp"
#endif

View File

@ -1501,3 +1501,5 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing)
#endif // QT_NO_DATASTREAM
QT_END_NAMESPACE
#include "moc_qeasingcurve.cpp"

View File

@ -3665,3 +3665,7 @@ QDebug operator<<(QDebug dbg, const QLocale &l)
}
#endif
QT_END_NAMESPACE
#ifndef QT_NO_QOBJECT
#include "moc_qlocale.cpp"
#endif

View File

@ -784,3 +784,5 @@ void QTimeLine::timerEvent(QTimerEvent *event)
}
QT_END_NAMESPACE
#include "moc_qtimeline.cpp"

138
util/includemocs/includemocs.pl Executable file
View File

@ -0,0 +1,138 @@
#!/usr/bin/perl
#############################################################################
##
## Copyright (C) 2017 Intel Corporation.
## Contact: https://www.qt.io/licensing/
##
## This file is the build configuration utility of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 as published by the Free Software
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################
use strict;
MAKEFILE: while ($_ = shift @ARGV) {
chdir($ENV{PWD});
open MAKEFILE, "<", $_
or die("Could not open Makefile");
print "includemocs.pl: Processing $_\n";
my $srcdir;
my $sourcesline;
# Find "SOURCES =" line
while (<MAKEFILE>) {
$srcdir = $1 if m,^# Project:\s+(.*)/[^/]+.pro,;
if (/^# Template:\s+(\w+)/) {
next MAKEFILE if $1 eq "subdirs";
}
if (/^SOURCES\s*=\s*(.*)/) {
$sourcesline = $1;
last;
}
}
if ($sourcesline =~ s/\s+\\//) {
# continuation
while (<MAKEFILE>) {
chomp;
/^\s*([^ ]+)/;
$sourcesline .= " $1";
last unless m/\\$/;
}
}
close MAKEFILE;
# Now parse the sources
my @mocs;
my @sources;
for (split(/ /, $sourcesline)) {
if (/\.moc\/(moc_.*\.cpp)/) {
push @mocs, $1;
} elsif (/^\.(rcc|uic)/) {
# ignore
} else {
push @sources, $_;
}
}
chdir($srcdir) or die("Where's $srcdir? $!");
for my $moc (@mocs) {
my $include = "#include \"$moc\"\n";
# Find a corresponding .cpp file to host the new #include
my $basename = ($moc =~ s/^moc_//r);
$basename =~ s/\.[^.]+//;
my @candidates = grep { m,\Q/$basename.\E, } @sources;
if (scalar @candidates == 0) {
# Try without a _p suffix
$basename =~ s/_p$//;
@candidates = grep { m,\Q/$basename.\E, } @sources;
}
if (scalar @candidates == 0) {
print STDERR "includemocs.pl: Cannot find .cpp file for $moc\n";
next;
}
my $cpp = $candidates[0];
undef @candidates;
#print "$moc -> $cpp\n";
open CPP, "<", $cpp
or die("Cannot open source $cpp: $!");
my @lines;
while (<CPP>) {
push @lines, $_;
next unless defined($include);
# Print the new include next to a pre-existing moc include
if (/#include \"moc_/ || /#include ".*\.moc"/) {
push @lines, $include;
undef $include;
}
}
close CPP;
if (defined($include)) {
# Try to insert the new #include between QT_END_NAMESPACE and any #endif lines
my $n = 0;
my $extrablank = "";
while (defined($include)) {
--$n;
$_ = $lines[$n];
if (/^#endif/) {
$extrablank = "\n";
next;
}
$_ .= "\n" unless /^$/;
splice @lines, $n, 1, ($_, $include, $extrablank);
undef $include;
}
}
# Write the file again
open CPP, ">", $cpp
or die("Cannot open source $cpp for writing: $!");
map { print CPP $_; } @lines;
close CPP;
}
}