mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
generic: optimize reading from files
QTextStream uses internal buffer Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
48a9346c3f
commit
6f34ee6809
2 changed files with 33 additions and 33 deletions
|
@ -302,24 +302,24 @@ QStringList KMimeTypeRepository::parents(const QString& mime)
|
|||
QFile qfile( fileName );
|
||||
//kDebug(7021) << "Now parsing" << fileName;
|
||||
if (qfile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream stream(&qfile);
|
||||
stream.setCodec("ISO-8859-1");
|
||||
while (!stream.atEnd()) {
|
||||
const QString line = stream.readLine();
|
||||
if (line.isEmpty() || line[0] == QLatin1Char('#'))
|
||||
while (!qfile.atEnd()) {
|
||||
const QByteArray line = qfile.readLine();
|
||||
if (line.isEmpty() || line[0] == '#')
|
||||
continue;
|
||||
const int pos = line.indexOf(QLatin1Char(' '));
|
||||
const int pos = line.indexOf(' ');
|
||||
if (pos == -1) // syntax error
|
||||
continue;
|
||||
const QString derivedTypeName = line.left(pos);
|
||||
KMimeType::Ptr derivedType = findMimeTypeByName(derivedTypeName, KMimeType::ResolveAliases);
|
||||
const QByteArray derivedTypeName = line.left(pos);
|
||||
const QString derivedTypeNameStr = QString::fromLatin1(derivedTypeName.constData(), derivedTypeName.size());
|
||||
KMimeType::Ptr derivedType = findMimeTypeByName(derivedTypeNameStr, KMimeType::ResolveAliases);
|
||||
if (!derivedType)
|
||||
kWarning(7012) << fileName << " refers to unknown mimetype " << derivedTypeName;
|
||||
kWarning(7012) << fileName << " refers to unknown mimetype " << derivedTypeNameStr;
|
||||
else {
|
||||
const QString parentTypeName = line.mid(pos+1);
|
||||
const QByteArray parentTypeName = line.mid(pos+1);
|
||||
const QString parentTypeNameStr = QString::fromLatin1(parentTypeName.constData(), parentTypeName.size());
|
||||
Q_ASSERT(!parentTypeName.isEmpty());
|
||||
//derivedType->setParentMimeType(parentTypeName);
|
||||
m_parents[derivedTypeName].append(parentTypeName);
|
||||
//derivedType->setParentMimeType(parentTypeNameStr);
|
||||
m_parents[derivedTypeNameStr].append(parentTypeNameStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -571,26 +571,26 @@ const KMimeTypeRepository::AliasesMap& KMimeTypeRepository::aliases()
|
|||
QFile qfile(fileName);
|
||||
//kDebug(7021) << "Now parsing" << fileName;
|
||||
if (qfile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream stream(&qfile);
|
||||
stream.setCodec("ISO-8859-1");
|
||||
while (!stream.atEnd()) {
|
||||
const QString line = stream.readLine();
|
||||
if (line.isEmpty() || line[0] == QLatin1Char('#'))
|
||||
while (!qfile.atEnd()) {
|
||||
const QByteArray line = qfile.readLine();
|
||||
if (line.isEmpty() || line[0] == '#')
|
||||
continue;
|
||||
const int pos = line.indexOf(QLatin1Char(' '));
|
||||
const int pos = line.indexOf(' ');
|
||||
if (pos == -1) // syntax error
|
||||
continue;
|
||||
const QString aliasTypeName = line.left(pos);
|
||||
const QString parentTypeName = line.mid(pos+1);
|
||||
const QByteArray aliasTypeName = line.left(pos);
|
||||
const QByteArray parentTypeName = line.mid(pos+1);
|
||||
Q_ASSERT(!aliasTypeName.isEmpty());
|
||||
Q_ASSERT(!parentTypeName.isEmpty());
|
||||
const QString aliasTypeNameStr = QString::fromLatin1(aliasTypeName.constData(), aliasTypeName.size());
|
||||
const QString parentTypeNameStr = QString::fromLatin1(parentTypeName.constData(), parentTypeName.size());
|
||||
|
||||
const KMimeType::Ptr realMimeType =
|
||||
findMimeTypeByName(aliasTypeName, KMimeType::DontResolveAlias);
|
||||
findMimeTypeByName(aliasTypeNameStr, KMimeType::DontResolveAlias);
|
||||
if (realMimeType) {
|
||||
//kDebug(servicesDebugArea()) << "Ignoring alias" << aliasTypeName << "because also defined as a real mimetype";
|
||||
//kDebug(servicesDebugArea()) << "Ignoring alias" << aliasTypeNameStr << "because also defined as a real mimetype";
|
||||
} else {
|
||||
m_aliases.insert(aliasTypeName, parentTypeName);
|
||||
m_aliases.insert(aliasTypeNameStr, parentTypeNameStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,24 +308,24 @@ void KIconLoaderGlobalData::parseGenericIconsFiles(const QString& fileName)
|
|||
{
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("ISO-8859-1");
|
||||
while (!stream.atEnd()) {
|
||||
const QString line = stream.readLine();
|
||||
while (!file.atEnd()) {
|
||||
const QByteArray line = file.readLine();
|
||||
if (line.isEmpty() || line[0] == '#')
|
||||
continue;
|
||||
const int pos = line.indexOf(':');
|
||||
if (pos == -1) // syntax error
|
||||
continue;
|
||||
QString mimeIcon = line.left(pos);
|
||||
const int slashindex = mimeIcon.indexOf(QLatin1Char('/'));
|
||||
QByteArray mimeIcon = line.left(pos);
|
||||
const int slashindex = mimeIcon.indexOf('/');
|
||||
if (slashindex != -1) {
|
||||
mimeIcon[slashindex] = QLatin1Char('-');
|
||||
mimeIcon[slashindex] = '-';
|
||||
}
|
||||
const QString mimeIconStr = QString::fromLatin1(mimeIcon.constData(), mimeIcon.size());
|
||||
|
||||
const QString genericIcon = line.mid(pos+1);
|
||||
m_genericIcons.insert(mimeIcon, genericIcon);
|
||||
//kDebug(264) << mimeIcon << "->" << genericIcon;
|
||||
const QByteArray genericIcon = line.mid(pos+1);
|
||||
const QString genericIconStr = QString::fromLatin1(genericIcon.constData(), genericIcon.size());
|
||||
m_genericIcons.insert(mimeIconStr, genericIconStr);
|
||||
//kDebug(264) << mimeIconStr << "->" << genericIconStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue