summaryrefslogtreecommitdiffstats
path: root/tools/linguist
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-05 17:21:47 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-08 12:02:10 (GMT)
commit8d9c9386be6e45fdf919a3ac5bf79f5cde315142 (patch)
tree14dda1989397a5c52f78e4872e6283663b52db7e /tools/linguist
parent777bf47da36292ffd37ae48a19796aafeb4d922e (diff)
downloadQt-8d9c9386be6e45fdf919a3ac5bf79f5cde315142.zip
Qt-8d9c9386be6e45fdf919a3ac5bf79f5cde315142.tar.gz
Qt-8d9c9386be6e45fdf919a3ac5bf79f5cde315142.tar.bz2
drastically improve load time of TS files
it isn't such a good idea to insert rows one by one into the model. so instead batch the "announcement" of new data. unloading single models is still slow, but that's a corner use case, so don't bother fixing it now, especially as it is harder to do it.
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/linguist/messagemodel.cpp48
-rw-r--r--tools/linguist/linguist/messagemodel.h2
2 files changed, 32 insertions, 18 deletions
diff --git a/tools/linguist/linguist/messagemodel.cpp b/tools/linguist/linguist/messagemodel.cpp
index 6572059..4e2b473 100644
--- a/tools/linguist/linguist/messagemodel.cpp
+++ b/tools/linguist/linguist/messagemodel.cpp
@@ -584,12 +584,16 @@ void MultiContextItem::putMessageItem(int pos, MessageItem *m)
m_messageLists.last()[pos] = m;
}
-void MultiContextItem::appendMessageItem(MessageItem *m)
+void MultiContextItem::appendMessageItems(const QList<MessageItem *> &m)
{
+ QList<MessageItem *> nullItems = m; // Basically, just a reservation
+ for (int i = 0; i < nullItems.count(); ++i)
+ nullItems[i] = 0;
for (int i = 0; i < m_messageLists.count() - 1; ++i)
- m_messageLists[i].append(0);
- m_messageLists.last().append(m);
- m_multiMessageList.append(MultiMessageItem(m));
+ m_messageLists[i] += nullItems;
+ m_messageLists.last() += m;
+ foreach (MessageItem *mi, m)
+ m_multiMessageList.append(MultiMessageItem(mi));
}
void MultiContextItem::removeMultiMessageItem(int pos)
@@ -710,33 +714,43 @@ void MultiDataModel::append(DataModel *dm, bool readWrite)
m_msgModel->endInsertColumns();
}
m_msgModel->endInsertColumns();
+ int appendedContexts = 0;
for (int i = 0; i < dm->contextCount(); ++i) {
ContextItem *c = dm->contextItem(i);
int mcx = findContextIndex(c->context());
if (mcx >= 0) {
MultiContextItem *mc = multiContextItem(mcx);
mc->assignLastModel(c, readWrite);
+ QList<MessageItem *> appendItems;
for (int j = 0; j < c->messageCount(); ++j) {
MessageItem *m = c->messageItem(j);
int msgIdx = mc->findMessage(m->text(), m->comment());
- if (msgIdx >= 0) {
+ if (msgIdx >= 0)
mc->putMessageItem(msgIdx, m);
- } else {
- int msgCnt = mc->messageCount();
- m_msgModel->beginInsertRows(m_msgModel->createIndex(mcx, 0, 0), msgCnt, msgCnt);
- mc->appendMessageItem(m);
- m_msgModel->endInsertRows();
- ++m_numMessages;
- }
+ else
+ appendItems << m;
+ }
+ if (!appendItems.isEmpty()) {
+ int msgCnt = mc->messageCount();
+ m_msgModel->beginInsertRows(m_msgModel->createIndex(mcx, 0, 0),
+ msgCnt, msgCnt + appendItems.size() - 1);
+ mc->appendMessageItems(appendItems);
+ m_msgModel->endInsertRows();
+ m_numMessages += appendItems.size();
}
} else {
- MultiContextItem item(modelCount() - 1, c, readWrite);
- m_msgModel->beginInsertRows(QModelIndex(), contextCount(), contextCount());
- m_multiContextList.append(item);
- m_msgModel->endInsertRows();
- m_numMessages += item.messageCount();
+ m_multiContextList << MultiContextItem(modelCount() - 1, c, readWrite);
+ m_numMessages += c->messageCount();
+ ++appendedContexts;
}
}
+ if (appendedContexts) {
+ // Do that en block to avoid itemview inefficiency. It doesn't hurt that we
+ // announce the availability of the data "long" after it was actually added.
+ m_msgModel->beginInsertRows(QModelIndex(),
+ contextCount() - appendedContexts, contextCount() - 1);
+ m_msgModel->endInsertRows();
+ }
dm->setWritable(readWrite);
updateCountsOnAdd(modelCount() - 1, readWrite);
connect(dm, SIGNAL(modifiedChanged()), SLOT(onModifiedChanged()));
diff --git a/tools/linguist/linguist/messagemodel.h b/tools/linguist/linguist/messagemodel.h
index 3e0107e..7d98873 100644
--- a/tools/linguist/linguist/messagemodel.h
+++ b/tools/linguist/linguist/messagemodel.h
@@ -332,7 +332,7 @@ private:
void removeModel(int pos);
void moveModel(int oldPos, int newPos); // newPos is *before* removing at oldPos
void putMessageItem(int pos, MessageItem *m);
- void appendMessageItem(MessageItem *m);
+ void appendMessageItems(const QList<MessageItem *> &m);
void removeMultiMessageItem(int pos);
void incrementFinishedCount() { ++m_finishedCount; }
void decrementFinishedCount() { --m_finishedCount; }