diff options
author | skym <skym@chromium.org> | 2015-12-22 13:13:51 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-22 21:14:31 +0000 |
commit | 295da3c3783957c25124d1337c4ceaac32050d1b (patch) | |
tree | a7cb62e14b1f9195e72745baf44459e8f0b4c182 | |
parent | f90eba63c122f8d1e1ef01627053c58da32d9de9 (diff) | |
download | chromium_src-295da3c3783957c25124d1337c4ceaac32050d1b.zip chromium_src-295da3c3783957c25124d1337c4ceaac32050d1b.tar.gz chromium_src-295da3c3783957c25124d1337c4ceaac32050d1b.tar.bz2 |
[Sync] replacing base::hash_map/set with std::unordered_map/set.
BUG=567280
Review URL: https://codereview.chromium.org/1506743006
Cr-Commit-Position: refs/heads/master@{#366650}
-rw-r--r-- | sync/syncable/directory.cc | 55 | ||||
-rw-r--r-- | sync/syncable/directory.h | 19 | ||||
-rw-r--r-- | sync/syncable/directory_backing_store.cc | 3 |
3 files changed, 26 insertions, 51 deletions
diff --git a/sync/syncable/directory.cc b/sync/syncable/directory.cc index 9c51f00..d81b861 100644 --- a/sync/syncable/directory.cc +++ b/sync/syncable/directory.cc @@ -776,49 +776,32 @@ bool Directory::PurgeEntriesWithTypeIn(ModelTypeSet disabled_types, if (!found_progress) return true; - // We iterate in two passes to avoid a bug in STLport (which is used in - // the Android build). There are some versions of that library where a - // hash_map's iterators can be invalidated when an item is erased from the - // hash_map. - // See http://sourceforge.net/p/stlport/bugs/239/. - - std::set<EntryKernel*> to_purge; for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); - it != kernel_->metahandles_map.end(); ++it) { - const sync_pb::EntitySpecifics& local_specifics = - it->second->ref(SPECIFICS); + it != kernel_->metahandles_map.end();) { + EntryKernel* entry = it->second; + const sync_pb::EntitySpecifics& local_specifics = entry->ref(SPECIFICS); const sync_pb::EntitySpecifics& server_specifics = - it->second->ref(SERVER_SPECIFICS); + entry->ref(SERVER_SPECIFICS); ModelType local_type = GetModelTypeFromSpecifics(local_specifics); ModelType server_type = GetModelTypeFromSpecifics(server_specifics); + // Increment the iterator before (potentially) calling DeleteEntry, + // otherwise our iterator may be invalidated. + ++it; + if ((IsRealDataType(local_type) && disabled_types.Has(local_type)) || (IsRealDataType(server_type) && disabled_types.Has(server_type))) { - to_purge.insert(it->second); - } - } - - for (std::set<EntryKernel*>::iterator it = to_purge.begin(); - it != to_purge.end(); ++it) { - EntryKernel* entry = *it; - - const sync_pb::EntitySpecifics& local_specifics = - (*it)->ref(SPECIFICS); - const sync_pb::EntitySpecifics& server_specifics = - (*it)->ref(SERVER_SPECIFICS); - ModelType local_type = GetModelTypeFromSpecifics(local_specifics); - ModelType server_type = GetModelTypeFromSpecifics(server_specifics); - - if (types_to_unapply.Has(local_type) || - types_to_unapply.Has(server_type)) { - UnapplyEntry(entry); - } else { - bool save_to_journal = - (types_to_journal.Has(local_type) || - types_to_journal.Has(server_type)) && - (delete_journal_->IsDeleteJournalEnabled(local_type) || - delete_journal_->IsDeleteJournalEnabled(server_type)); - DeleteEntry(lock, save_to_journal, entry, &entries_to_journal); + if (types_to_unapply.Has(local_type) || + types_to_unapply.Has(server_type)) { + UnapplyEntry(entry); + } else { + bool save_to_journal = + (types_to_journal.Has(local_type) || + types_to_journal.Has(server_type)) && + (delete_journal_->IsDeleteJournalEnabled(local_type) || + delete_journal_->IsDeleteJournalEnabled(server_type)); + DeleteEntry(lock, save_to_journal, entry, &entries_to_journal); + } } } diff --git a/sync/syncable/directory.h b/sync/syncable/directory.h index 06dbc5b..0884b42 100644 --- a/sync/syncable/directory.h +++ b/sync/syncable/directory.h @@ -11,6 +11,7 @@ #include <deque> #include <set> #include <string> +#include <unordered_map> #include <vector> #include "base/callback.h" @@ -62,21 +63,11 @@ class SYNC_EXPORT Directory { public: typedef std::vector<int64_t> Metahandles; - // TODO(skym): Convert this hash_map usage to unordered_map, crbug/567280. - // Be careful when using these hash_map containers. According to the spec, - // inserting into them may invalidate all iterators. - // - // It gets worse, though. The Anroid STL library has a bug that means it may - // invalidate all iterators when you erase from the map, too. That means that - // you can't iterate while erasing. STLDeleteElements(), std::remove_if(), - // and other similar functions are off-limits too, until this bug is fixed. - // - // See http://sourceforge.net/p/stlport/bugs/239/. - typedef base::hash_map<int64_t, EntryKernel*> MetahandlesMap; - typedef base::hash_map<std::string, EntryKernel*> IdsMap; - typedef base::hash_map<std::string, EntryKernel*> TagsMap; + typedef std::unordered_map<int64_t, EntryKernel*> MetahandlesMap; + typedef std::unordered_map<std::string, EntryKernel*> IdsMap; + typedef std::unordered_map<std::string, EntryKernel*> TagsMap; typedef std::string AttachmentIdUniqueId; - typedef base::hash_map<AttachmentIdUniqueId, MetahandleSet> + typedef std::unordered_map<AttachmentIdUniqueId, MetahandleSet> IndexByAttachmentId; static const base::FilePath::CharType kSyncDatabaseFilename[]; diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc index 9272ae5..2ee31e9 100644 --- a/sync/syncable/directory_backing_store.cc +++ b/sync/syncable/directory_backing_store.cc @@ -8,6 +8,7 @@ #include <stdint.h> #include <limits> +#include <unordered_set> #include "base/base64.h" #include "base/logging.h" @@ -1636,7 +1637,7 @@ bool DirectoryBackingStore::CreateShareInfoTableVersion71( bool DirectoryBackingStore::VerifyReferenceIntegrity( const Directory::MetahandlesMap* handles_map) { TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck"); - typedef base::hash_set<std::string> IdsSet; + typedef std::unordered_set<std::string> IdsSet; IdsSet ids_set; bool is_ok = true; |