Use QHash for temporary entry/group containers.

Closes #11
This commit is contained in:
Felix Geyer 2012-04-22 12:29:18 +02:00
parent ef26065a99
commit baed7d76cf
2 changed files with 31 additions and 30 deletions

View File

@ -82,18 +82,21 @@ void KeePass2XmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Ra
QHash<QString, QPair<Entry*, QString> >::const_iterator i;
for (i = m_binaryMap.constBegin(); i != m_binaryMap.constEnd(); ++i) {
QPair<Entry*, QString> target = i.value();
const QPair<Entry*, QString>& target = i.value();
target.first->attachments()->set(target.second, m_binaryPool[i.key()]);
}
m_meta->setUpdateDatetime(true);
Q_FOREACH (Group* group, m_groups) {
group->setUpdateTimeinfo(true);
QHash<Uuid, Group*>::const_iterator iGroup;
for (iGroup = m_groups.constBegin(); iGroup != m_groups.constEnd(); ++iGroup) {
iGroup.value()->setUpdateTimeinfo(true);
}
Q_FOREACH (Entry* entry, m_entries) {
entry->setUpdateTimeinfo(true);
Q_FOREACH(Entry* histEntry, entry->historyItems()) {
QHash<Uuid, Entry*>::const_iterator iEntry;
for (iEntry = m_entries.constBegin(); iEntry != m_entries.constEnd(); ++iEntry) {
iEntry.value()->setUpdateTimeinfo(true);
Q_FOREACH (Entry* histEntry, iEntry.value()->historyItems()) {
histEntry->setUpdateTimeinfo(true);
}
}
@ -895,18 +898,17 @@ Group* KeePass2XmlReader::getGroup(const Uuid& uuid)
return 0;
}
Q_FOREACH (Group* group, m_groups) {
if (group->uuid() == uuid) {
return group;
}
if (m_groups.contains(uuid)) {
return m_groups.value(uuid);
}
else {
Group* group = new Group();
group->setUpdateTimeinfo(false);
group->setUuid(uuid);
group->setParent(m_tmpParent);
m_groups.insert(uuid, group);
return group;
}
Group* group = new Group();
group->setUpdateTimeinfo(false);
group->setUuid(uuid);
group->setParent(m_tmpParent);
m_groups << group;
return group;
}
Entry* KeePass2XmlReader::getEntry(const Uuid& uuid)
@ -915,18 +917,17 @@ Entry* KeePass2XmlReader::getEntry(const Uuid& uuid)
return 0;
}
Q_FOREACH (Entry* entry, m_entries) {
if (entry->uuid() == uuid) {
return entry;
}
if (m_entries.contains(uuid)) {
return m_entries.value(uuid);
}
else {
Entry* entry = new Entry();
entry->setUpdateTimeinfo(false);
entry->setUuid(uuid);
entry->setGroup(m_tmpParent);
m_entries.insert(uuid, entry);
return entry;
}
Entry* entry = new Entry();
entry->setUpdateTimeinfo(false);
entry->setUuid(uuid);
entry->setGroup(m_tmpParent);
m_entries << entry;
return entry;
}
void KeePass2XmlReader::raiseError(int internalNumber)

View File

@ -87,8 +87,8 @@ private:
Database* m_db;
Metadata* m_meta;
Group* m_tmpParent;
QList<Group*> m_groups;
QList<Entry*> m_entries;
QHash<Uuid, Group*> m_groups;
QHash<Uuid, Entry*> m_entries;
QHash<QString, QByteArray> m_binaryPool;
QHash<QString, QPair<Entry*, QString> > m_binaryMap;
};