From f7c68f6baf104729e8d2fb3a0693b3c59928f8d3 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Mon, 19 Aug 2013 15:47:51 +0200 Subject: C++: change working-copy to work on UTF-8 encoded QByteArrays. These not only take less space than UTF-16 encoded QStrings, but due to the caching in the CppEditorSupport also take less time to build. This patch also fixes a number of possible encoding issues, where files and constant strings were (falsely) assumed to be UTF-8. Change-Id: Ib6f91c9a94ebed5b5dfbd4eb2998825c62c72784 Reviewed-by: Nikolai Kosjar Reviewed-by: hjk --- src/plugins/cpptools/cpppreprocessor.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/plugins/cpptools/cpppreprocessor.cpp') diff --git a/src/plugins/cpptools/cpppreprocessor.cpp b/src/plugins/cpptools/cpppreprocessor.cpp index 417363db3c..85ba300fc3 100644 --- a/src/plugins/cpptools/cpppreprocessor.cpp +++ b/src/plugins/cpptools/cpppreprocessor.cpp @@ -3,6 +3,7 @@ #include "cppmodelmanager.h" #include +#include #include @@ -154,14 +155,14 @@ void CppPreprocessor::resetEnvironment() } void CppPreprocessor::getFileContents(const QString &absoluteFilePath, - QString *contents, + QByteArray *contents, unsigned *revision) const { if (absoluteFilePath.isEmpty()) return; if (m_workingCopy.contains(absoluteFilePath)) { - const QPair entry = m_workingCopy.get(absoluteFilePath); + const QPair entry = m_workingCopy.get(absoluteFilePath); if (contents) *contents = entry.first; if (revision) @@ -169,16 +170,11 @@ void CppPreprocessor::getFileContents(const QString &absoluteFilePath, return; } - QFile file(absoluteFilePath); - if (file.open(QFile::ReadOnly | QFile::Text)) { - QTextStream stream(&file); - stream.setCodec(Core::EditorManager::defaultTextCodec()); - if (contents) - *contents = stream.readAll(); - if (revision) - *revision = 0; - file.close(); - } + QString errStr; + if (contents) + Utils::TextFileFormat::readFileUTF8(absoluteFilePath, contents, &errStr); + if (revision) + *revision = 0; } bool CppPreprocessor::checkFile(const QString &absoluteFilePath) const @@ -370,7 +366,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu m_included.insert(absoluteFileName); unsigned editorRevision = 0; - QString contents; + QByteArray contents; getFileContents(absoluteFileName, &contents, &editorRevision); if (m_currentDoc) { if (contents.isEmpty() && !QFileInfo(absoluteFileName).isAbsolute()) { -- cgit v1.2.1