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

Unified Diff: ios/web/navigation/navigation_manager_impl.mm

Issue 2526093002: [ios] Improved GetIndexForOffset performance to large offsets. (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | ios/web/navigation/navigation_manager_impl_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/navigation/navigation_manager_impl.mm
diff --git a/ios/web/navigation/navigation_manager_impl.mm b/ios/web/navigation/navigation_manager_impl.mm
index 76b42d450bcc185200248bea3b3530fe79411de4..15ea6600c3ba95a11fa2e16b062eca07402d0e0c 100644
--- a/ios/web/navigation/navigation_manager_impl.mm
+++ b/ios/web/navigation/navigation_manager_impl.mm
@@ -350,7 +350,7 @@ int NavigationManagerImpl::GetIndexForOffset(int offset) const {
offset++;
}
- while (offset < 0) {
+ while (offset < 0 && result > 0) {
// To stop the user getting 'stuck' on redirecting pages they weren't
// even aware existed, it is necessary to pass over pages that would
// immediately result in a redirect (the entry *before* the redirected
@@ -361,6 +361,11 @@ int NavigationManagerImpl::GetIndexForOffset(int offset) const {
--result;
++offset;
}
+ // Result may be out of bounds, so stop trying to skip redirect items and
+ // simply add the remainder.
+ result += offset;
+ if (result > GetItemCount() /* overflow */)
+ result = INT_MIN;
} else if (offset > 0) {
if (GetPendingItem() && [session_controller_ pendingEntryIndex] == -1) {
// Chrome for iOS does not allow forward navigation if there is another
@@ -372,8 +377,7 @@ int NavigationManagerImpl::GetIndexForOffset(int offset) const {
// pending index.
return INT_MAX;
}
-
- while (offset > 0) {
+ while (offset > 0 && result < GetItemCount()) {
++result;
--offset;
// As with going back, skip over redirects.
@@ -381,6 +385,11 @@ int NavigationManagerImpl::GetIndexForOffset(int offset) const {
++result;
}
}
+ // Result may be out of bounds, so stop trying to skip redirect items and
+ // simply add the remainder.
+ result += offset;
+ if (result < 0 /* overflow */)
+ result = INT_MAX;
}
return result;
« no previous file with comments | « no previous file | ios/web/navigation/navigation_manager_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698