summaryrefslogtreecommitdiffstats
path: root/tools/linguist
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-06-01 16:19:57 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-06-01 19:34:43 (GMT)
commita107d3e22e128ec343d82f902de4c6ee0e33435f (patch)
tree6dde67241aa06190ce3353d6dccef50c37ec1245 /tools/linguist
parentad23439b7e112aa8a36f34e7b16224dcab742147 (diff)
downloadQt-a107d3e22e128ec343d82f902de4c6ee0e33435f.zip
Qt-a107d3e22e128ec343d82f902de4c6ee0e33435f.tar.gz
Qt-a107d3e22e128ec343d82f902de4c6ee0e33435f.tar.bz2
optimization: make the Translator::find() api index-based
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/lupdate/merge.cpp52
-rw-r--r--tools/linguist/shared/translator.cpp16
-rw-r--r--tools/linguist/shared/translator.h5
3 files changed, 38 insertions, 35 deletions
diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp
index 2d5230b..1c992c3 100644
--- a/tools/linguist/lupdate/merge.cpp
+++ b/tools/linguist/lupdate/merge.cpp
@@ -348,11 +348,11 @@ Translator merge(const Translator &tor, const Translator &virginTor,
if (m.sourceText().isEmpty() && m.id().isEmpty()) {
// context/file comment
- TranslatorMessage mv = virginTor.find(m.context());
- if (!mv.isNull())
- m.setComment(mv.comment());
+ int mvi = virginTor.find(m.context());
+ if (mvi >= 0)
+ m.setComment(virginTor.constMessage(mvi).comment());
} else {
- TranslatorMessage mv;
+ const TranslatorMessage *mv;
int mvi = virginTor.find(m);
if (mvi < 0) {
if (!(options & HeuristicSimilarText)) {
@@ -362,16 +362,17 @@ Translator merge(const Translator &tor, const Translator &virginTor,
obsoleted++;
m.clearReferences();
} else {
- mv = virginTor.find(m.context(), m.comment(), m.allReferences());
- if (mv.isNull()) {
+ mvi = virginTor.find(m.context(), m.comment(), m.allReferences());
+ if (mvi < 0) {
// did not find it in the virgin, mark it as obsolete
goto makeObsolete;
} else {
+ mv = &virginTor.constMessage(mvi);
// Do not just accept it if its on the same line number,
// but different source text.
// Also check if the texts are more or less similar before
// we consider them to represent the same message...
- if (getSimilarityScore(m.sourceText(), mv.sourceText()) >= textSimilarityThreshold) {
+ if (getSimilarityScore(m.sourceText(), mv->sourceText()) >= textSimilarityThreshold) {
// It is just slightly modified, assume that it is the same string
// Mark it as unfinished. (Since the source text
@@ -382,7 +383,7 @@ Translator merge(const Translator &tor, const Translator &virginTor,
outdateSource:
m.setOldSourceText(m.sourceText());
- m.setSourceText(mv.sourceText());
+ m.setSourceText(mv->sourceText());
const QString &oldpluralsource = m.extra(QLatin1String("po-msgid_plural"));
if (!oldpluralsource.isEmpty()) {
m.setExtra(QLatin1String("po-old_msgid_plural"), oldpluralsource);
@@ -397,22 +398,22 @@ Translator merge(const Translator &tor, const Translator &virginTor,
}
}
} else {
- mv = virginTor.message(mvi);
- if (!mv.id().isEmpty()
- && (mv.context() != m.context()
- || mv.sourceText() != m.sourceText()
- || mv.comment() != m.comment())) {
+ mv = &virginTor.message(mvi);
+ if (!mv->id().isEmpty()
+ && (mv->context() != m.context()
+ || mv->sourceText() != m.sourceText()
+ || mv->comment() != m.comment())) {
known++;
newType = TranslatorMessage::Unfinished;
- m.setContext(mv.context());
- m.setComment(mv.comment());
- if (mv.sourceText() != m.sourceText())
+ m.setContext(mv->context());
+ m.setComment(mv->comment());
+ if (mv->sourceText() != m.sourceText())
goto outdateSource;
} else {
switch (m.type()) {
case TranslatorMessage::Finished:
default:
- if (m.isPlural() == mv.isPlural()) {
+ if (m.isPlural() == mv->isPlural()) {
newType = TranslatorMessage::Finished;
} else {
newType = TranslatorMessage::Unfinished;
@@ -435,11 +436,11 @@ Translator merge(const Translator &tor, const Translator &virginTor,
// have the <location> element.
// why not use operator=()? Because it overwrites e.g. userData.
copyAttribs:
- m.setReferences(mv.allReferences());
- m.setPlural(mv.isPlural());
- m.setUtf8(mv.isUtf8());
- m.setExtraComment(mv.extraComment());
- m.setId(mv.id());
+ m.setReferences(mv->allReferences());
+ m.setPlural(mv->isPlural());
+ m.setUtf8(mv->isUtf8());
+ m.setExtraComment(mv->extraComment());
+ m.setId(mv->id());
}
}
@@ -459,9 +460,10 @@ Translator merge(const Translator &tor, const Translator &virginTor,
if (tor.find(mv) >= 0)
continue;
if (options & HeuristicSimilarText) {
- TranslatorMessage m = tor.find(mv.context(), mv.comment(), mv.allReferences());
- if (!m.isNull()) {
- if (getSimilarityScore(m.sourceText(), mv.sourceText()) >= textSimilarityThreshold)
+ int mi = tor.find(mv.context(), mv.comment(), mv.allReferences());
+ if (mi >= 0) {
+ if (getSimilarityScore(tor.constMessage(mi).sourceText(), mv.sourceText())
+ >= textSimilarityThreshold)
continue;
}
}
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index 2a15fe7..91a5a26 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -346,7 +346,7 @@ int Translator::find(const TranslatorMessage &msg) const
return -1;
}
-TranslatorMessage Translator::find(const QString &context,
+int Translator::find(const QString &context,
const QString &comment, const TranslatorMessage::References &refs) const
{
if (!refs.isEmpty()) {
@@ -355,10 +355,10 @@ TranslatorMessage Translator::find(const QString &context,
foreach (const TranslatorMessage::Reference &itref, it->allReferences())
foreach (const TranslatorMessage::Reference &ref, refs)
if (itref == ref)
- return *it;
+ return it - m_messages.constBegin();
}
}
- return TranslatorMessage();
+ return -1;
}
bool Translator::contains(const QString &context) const
@@ -369,12 +369,12 @@ bool Translator::contains(const QString &context) const
return false;
}
-TranslatorMessage Translator::find(const QString &context) const
+int Translator::find(const QString &context) const
{
- foreach (const TranslatorMessage &msg, m_messages)
- if (msg.context() == context && msg.sourceText().isEmpty() && msg.id().isEmpty())
- return msg;
- return TranslatorMessage();
+ for (TMM::ConstIterator it = m_messages.constBegin(); it != m_messages.constEnd(); ++it)
+ if (it->context() == context && it->sourceText().isEmpty() && it->id().isEmpty())
+ return it - m_messages.constBegin();
+ return -1;
}
void Translator::stripObsoleteMessages()
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index b9bc94c..41f0396 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -127,11 +127,11 @@ public:
bool save(const QString &filename, ConversionData &err, const QString &format /* = "auto" */) const;
int find(const TranslatorMessage &msg) const;
- TranslatorMessage find(const QString &context,
+ int find(const QString &context,
const QString &comment, const TranslatorMessage::References &refs) const;
bool contains(const QString &context) const;
- TranslatorMessage find(const QString &context) const;
+ int find(const QString &context) const;
void replaceSorted(const TranslatorMessage &msg);
void extend(const TranslatorMessage &msg); // Only for single-location messages
@@ -178,6 +178,7 @@ public:
int messageCount() const { return m_messages.size(); }
TranslatorMessage &message(int i) { return m_messages[i]; }
const TranslatorMessage &message(int i) const { return m_messages.at(i); }
+ const TranslatorMessage &constMessage(int i) const { return m_messages.at(i); }
void dump() const;
// additional file format specific data