summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/preprocessor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/moc/preprocessor.cpp')
-rw-r--r--src/tools/moc/preprocessor.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index 087b064c0f..ff435085b4 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -52,11 +52,12 @@ static QByteArray cleaned(const QByteArray &input)
QByteArray result;
result.reserve(input.size());
const char *data = input.constData();
+ const char *end = input.constData() + input.size();
char *output = result.data();
int newlines = 0;
- while (*data) {
- while (*data && is_space(*data))
+ while (data != end) {
+ while (data != end && is_space(*data))
++data;
bool takeLine = (*data == '#');
if (*data == '%' && *(data+1) == ':') {
@@ -66,15 +67,15 @@ static QByteArray cleaned(const QByteArray &input)
if (takeLine) {
*output = '#';
++output;
- do ++data; while (*data && is_space(*data));
+ do ++data; while (data != end && is_space(*data));
}
- while (*data) {
+ while (data != end) {
// handle \\\n, \\\r\n and \\\r
if (*data == '\\') {
if (*(data + 1) == '\r') {
++data;
}
- if (*data && (*(data + 1) == '\n' || (*data) == '\r')) {
+ if (data != end && (*(data + 1) == '\n' || (*data) == '\r')) {
++newlines;
data += 1;
if (*data != '\r')
@@ -964,6 +965,13 @@ int Preprocessor::evaluateCondition()
return expression.value();
}
+static QByteArray readOrMapFile(QFile *file)
+{
+ const qint64 size = file->size();
+ char *rawInput = reinterpret_cast<char*>(file->map(0, size));
+ return rawInput ? QByteArray::fromRawData(rawInput, size) : file->readAll();
+}
+
void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
{
currentFilenames.push(filename);
@@ -1020,7 +1028,8 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
if (!file.open(QFile::ReadOnly))
continue;
- QByteArray input = file.readAll();
+ QByteArray input = readOrMapFile(&file);
+
file.close();
if (input.isEmpty())
continue;
@@ -1157,9 +1166,10 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
currentFilenames.pop();
}
-Symbols Preprocessor::preprocessed(const QByteArray &filename, QIODevice *file)
+Symbols Preprocessor::preprocessed(const QByteArray &filename, QFile *file)
{
- QByteArray input = file->readAll();
+ QByteArray input = readOrMapFile(file);
+
if (input.isEmpty())
return symbols;