Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Unified Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.mm

Issue 2612773002: [ios] Style cleanups in tab switcher code.
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.mm
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.mm b/ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.mm
index af2c65df11f8e3174624a447b381534401e90863..b22cef531ae6e92df702b1227106336eae7dbb2a 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.mm
@@ -27,29 +27,29 @@ UIImage* DefaultFaviconImage() {
enum BacktrackOperation { NOTHING, SUBSTITUTION, DELETION, INSERTION };
BacktrackOperation BacktrackOperationInCostMatrix(
- std::vector<std::vector<int>> const& costMatrix,
- size_t finalIndex,
- size_t initialIndex) {
- DCHECK(finalIndex || initialIndex);
- DCHECK(initialIndex < costMatrix.size());
- DCHECK(finalIndex < costMatrix[initialIndex].size());
-
- if (finalIndex == 0)
+ std::vector<std::vector<int>> const& cost_matrix,
+ size_t final_index,
+ size_t initial_index) {
+ DCHECK(final_index || initial_index);
+ DCHECK(initial_index < cost_matrix.size());
+ DCHECK(final_index < cost_matrix[initial_index].size());
+
+ if (final_index == 0)
return DELETION;
- if (initialIndex == 0)
+ if (initial_index == 0)
return INSERTION;
- int currentCost = costMatrix[initialIndex][finalIndex];
+ int currentCost = cost_matrix[initial_index][final_index];
- int costBeforeInsertion = costMatrix[initialIndex][finalIndex - 1];
+ int costBeforeInsertion = cost_matrix[initial_index][final_index - 1];
if (costBeforeInsertion + 1 == currentCost)
return INSERTION;
- int costBeforeDeletion = costMatrix[initialIndex - 1][finalIndex];
+ int costBeforeDeletion = cost_matrix[initial_index - 1][final_index];
if (costBeforeDeletion + 1 == currentCost)
return DELETION;
- int costBeforeSubstitution = costMatrix[initialIndex - 1][finalIndex - 1];
+ int costBeforeSubstitution = cost_matrix[initial_index - 1][final_index - 1];
if (costBeforeSubstitution == currentCost)
return NOTHING;
@@ -72,10 +72,10 @@ void TabSwitcherGetFavicon(GURL const& url,
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
dispatch_async(queue, ^{
- NSData* pngData =
+ NSData* png_data =
[NSData dataWithBytes:favicon->front() length:favicon->size()];
base::scoped_nsobject<UIImage> image(
- [[UIImage alloc] initWithData:pngData]);
+ [[UIImage alloc] initWithData:png_data]);
dispatch_async(dispatch_get_main_queue(), ^{
// |UIImage initWithData:| may return nil.
if (image) {
@@ -120,62 +120,65 @@ void TabSwitcherMinimalReplacementOperations(std::vector<size_t> const& initial,
// algorithm.
// https://en.wikipedia.org/wiki/Levenshtein_distance
- const size_t initialSize = initial.size() + 1;
- const size_t finalSize = final.size() + 1;
+ const size_t initial_size = initial.size() + 1;
+ const size_t final_size = final.size() + 1;
- std::vector<std::vector<int>> costMatrix(initialSize,
- std::vector<int>(finalSize));
+ std::vector<std::vector<int>> cost_matrix(initial_size,
+ std::vector<int>(final_size));
- for (size_t i = 1; i < initialSize; i++)
- costMatrix[i][0] = i;
- for (size_t i = 1; i < finalSize; i++)
- costMatrix[0][i] = i;
+ for (size_t i = 1; i < initial_size; i++)
+ cost_matrix[i][0] = i;
+ for (size_t i = 1; i < final_size; i++)
+ cost_matrix[0][i] = i;
// Step 1: Generate cost matrix.
- for (size_t initialIndex = 1; initialIndex < initialSize; initialIndex++) {
- for (size_t finalIndex = 1; finalIndex < finalSize; finalIndex++) {
- if (initial[initialIndex - 1] == final[finalIndex - 1]) {
- costMatrix[initialIndex][finalIndex] =
- costMatrix[initialIndex - 1][finalIndex - 1];
+ for (size_t initial_index = 1; initial_index < initial_size;
+ initial_index++) {
+ for (size_t final_index = 1; final_index < final_size; final_index++) {
+ if (initial[initial_index - 1] == final[final_index - 1]) {
+ cost_matrix[initial_index][final_index] =
+ cost_matrix[initial_index - 1][final_index - 1];
} else {
- int costAfterSubstitution =
- costMatrix[initialIndex - 1][finalIndex - 1] + 1;
- int costAfterInsertion = costMatrix[initialIndex][finalIndex - 1] + 1;
- int costAfterDeletion = costMatrix[initialIndex - 1][finalIndex] + 1;
- costMatrix[initialIndex][finalIndex] =
- std::min(std::min(costAfterDeletion, costAfterInsertion),
- costAfterSubstitution);
+ int cost_after_substitution =
+ cost_matrix[initial_index - 1][final_index - 1] + 1;
+ int cost_after_insertion =
+ cost_matrix[initial_index][final_index - 1] + 1;
+ int cost_after_deletion =
+ cost_matrix[initial_index - 1][final_index] + 1;
+ cost_matrix[initial_index][final_index] =
+ std::min(std::min(cost_after_deletion, cost_after_insertion),
+ cost_after_substitution);
}
}
}
// Step 2: Backtrack to find the operations (deletion, insertion,
// substitution).
- size_t initialIndex = initialSize - 1;
- size_t finalIndex = finalSize - 1;
- while (initialIndex != 0 || finalIndex != 0) {
+ size_t initial_index = initial_size - 1;
+ size_t final_index = final_size - 1;
+ while (initial_index != 0 || final_index != 0) {
BacktrackOperation op =
- BacktrackOperationInCostMatrix(costMatrix, finalIndex, initialIndex);
+ BacktrackOperationInCostMatrix(cost_matrix, final_index, initial_index);
switch (op) {
case SUBSTITUTION:
- finalIndex--;
- initialIndex--;
+ final_index--;
+ initial_index--;
// The substitution is relative to |initial|.
- substitutions->push_back(initialIndex);
+ substitutions->push_back(initial_index);
break;
case DELETION:
- initialIndex--;
+ initial_index--;
// The deletion is relative to |initial|.
- deletions->push_back(initialIndex);
+ deletions->push_back(initial_index);
break;
case INSERTION:
- finalIndex--;
+ final_index--;
// The insertion is relative to |final|.
- insertions->push_back(finalIndex);
+ insertions->push_back(final_index);
break;
case NOTHING:
- finalIndex--;
- initialIndex--;
+ final_index--;
+ initial_index--;
break;
}
}
« no previous file with comments | « ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698