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

Side by Side Diff: chrome/browser/ui/cocoa/applescript/bookmark_folder_applescript.mm

Issue 1105413002: Avoid conversion of index to BookmarkNode pointer unnacessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/applescript/bookmark_folder_applescript.h" 5 #import "chrome/browser/ui/cocoa/applescript/bookmark_folder_applescript.h"
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #import "base/strings/string16.h" 8 #import "base/strings/string16.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #import "chrome/browser/ui/cocoa/applescript/bookmark_item_applescript.h" 10 #import "chrome/browser/ui/cocoa/applescript/bookmark_item_applescript.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 [aBookmarkFolder setBookmarkNode:node]; 79 [aBookmarkFolder setBookmarkNode:node];
80 } 80 }
81 81
82 - (void)removeFromBookmarkFoldersAtIndex:(int)index { 82 - (void)removeFromBookmarkFoldersAtIndex:(int)index {
83 int position = [self calculatePositionOfBookmarkFolderAt:index]; 83 int position = [self calculatePositionOfBookmarkFolderAt:index];
84 84
85 BookmarkModel* model = [self bookmarkModel]; 85 BookmarkModel* model = [self bookmarkModel];
86 if (!model) 86 if (!model)
87 return; 87 return;
88 88
89 model->Remove(bookmarkNode_, position); 89 model->Remove(bookmarkNode_->GetChild(position));
90 } 90 }
91 91
92 - (NSArray*)bookmarkItems { 92 - (NSArray*)bookmarkItems {
93 NSMutableArray* bookmarkItems = [NSMutableArray 93 NSMutableArray* bookmarkItems = [NSMutableArray
94 arrayWithCapacity:bookmarkNode_->child_count()]; 94 arrayWithCapacity:bookmarkNode_->child_count()];
95 95
96 for (int i = 0; i < bookmarkNode_->child_count(); ++i) { 96 for (int i = 0; i < bookmarkNode_->child_count(); ++i) {
97 const BookmarkNode* node = bookmarkNode_->GetChild(i); 97 const BookmarkNode* node = bookmarkNode_->GetChild(i);
98 98
99 if (!node->is_url()) 99 if (!node->is_url())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 [aBookmarkItem setBookmarkNode:node]; 166 [aBookmarkItem setBookmarkNode:node];
167 } 167 }
168 168
169 - (void)removeFromBookmarkItemsAtIndex:(int)index { 169 - (void)removeFromBookmarkItemsAtIndex:(int)index {
170 int position = [self calculatePositionOfBookmarkItemAt:index]; 170 int position = [self calculatePositionOfBookmarkItemAt:index];
171 171
172 BookmarkModel* model = [self bookmarkModel]; 172 BookmarkModel* model = [self bookmarkModel];
173 if (!model) 173 if (!model)
174 return; 174 return;
175 175
176 model->Remove(bookmarkNode_, position); 176 model->Remove(bookmarkNode_->GetChild(position));
177 } 177 }
178 178
179 - (int)calculatePositionOfBookmarkFolderAt:(int)index { 179 - (int)calculatePositionOfBookmarkFolderAt:(int)index {
180 // Traverse through all the child nodes till the required node is found and 180 // Traverse through all the child nodes till the required node is found and
181 // return its position. 181 // return its position.
182 // AppleScript is 1-based therefore index is incremented by 1. 182 // AppleScript is 1-based therefore index is incremented by 1.
183 ++index; 183 ++index;
184 int count = -1; 184 int count = -1;
185 while (index) { 185 while (index) {
186 if (bookmarkNode_->GetChild(++count)->is_folder()) 186 if (bookmarkNode_->GetChild(++count)->is_folder())
187 --index; 187 --index;
188 } 188 }
189 return count; 189 return count;
190 } 190 }
191 191
192 - (int)calculatePositionOfBookmarkItemAt:(int)index { 192 - (int)calculatePositionOfBookmarkItemAt:(int)index {
193 // Traverse through all the child nodes till the required node is found and 193 // Traverse through all the child nodes till the required node is found and
194 // return its position. 194 // return its position.
195 // AppleScript is 1-based therefore index is incremented by 1. 195 // AppleScript is 1-based therefore index is incremented by 1.
196 ++index; 196 ++index;
197 int count = -1; 197 int count = -1;
198 while (index) { 198 while (index) {
199 if (bookmarkNode_->GetChild(++count)->is_url()) 199 if (bookmarkNode_->GetChild(++count)->is_url())
200 --index; 200 --index;
201 } 201 }
202 return count; 202 return count;
203 } 203 }
204 204
205 @end 205 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698