зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1596129 - Use range-based for, std::find_if, std::unique and avoid insert-sort on a nsTArray in IDBDatabase::Transaction. r=dom-workers-and-storage-reviewers,ytausky
Depends on D52864 Differential Revision: https://phabricator.services.mozilla.com/D52865 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
2ac5e4e5ab
Коммит
be00b51583
|
@ -556,33 +556,26 @@ nsresult IDBDatabase::Transaction(JSContext* aCx,
|
|||
nsTArray<nsString> sortedStoreNames;
|
||||
sortedStoreNames.SetCapacity(nameCount);
|
||||
|
||||
// Check to make sure the object store names we collected actually exist.
|
||||
for (uint32_t nameIndex = 0; nameIndex < nameCount; nameIndex++) {
|
||||
const nsString& name = storeNames[nameIndex];
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (uint32_t objCount = objectStores.Length(), objIndex = 0;
|
||||
objIndex < objCount; objIndex++) {
|
||||
if (objectStores[objIndex].metadata().name() == name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
// While collecting object store names, check if the corresponding object
|
||||
// stores actually exist.
|
||||
const auto begin = objectStores.cbegin();
|
||||
const auto end = objectStores.cend();
|
||||
for (const auto& name : storeNames) {
|
||||
const auto foundIt =
|
||||
std::find_if(begin, end, [&name](const auto& objectStore) {
|
||||
return objectStore.metadata().name() == name;
|
||||
});
|
||||
if (foundIt == end) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
sortedStoreNames.InsertElementSorted(name);
|
||||
sortedStoreNames.EmplaceBack(name);
|
||||
}
|
||||
sortedStoreNames.Sort();
|
||||
|
||||
// Remove any duplicates.
|
||||
for (uint32_t nameIndex = nameCount - 1; nameIndex > 0; nameIndex--) {
|
||||
if (sortedStoreNames[nameIndex] == sortedStoreNames[nameIndex - 1]) {
|
||||
sortedStoreNames.RemoveElementAt(nameIndex);
|
||||
}
|
||||
}
|
||||
sortedStoreNames.SetLength(
|
||||
std::unique(sortedStoreNames.begin(), sortedStoreNames.end()).GetIndex());
|
||||
|
||||
IDBTransaction::Mode mode;
|
||||
switch (aMode) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче