Skip to content

Commit 203adf4

Browse files
committed
perf(tabbookmark): apply short circuit evaluation to HandleBookmark
We do not and should not call `IsOnNewTab` if `IsOnBookmarkBar` is false. Otherwise, even though users click on web pages, the code may still call `IsOnNewTab` which is unnecessary and may lead to incorrect results.
1 parent dea5944 commit 203adf4

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/tabbookmark.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,34 @@ bool HandleBookmark(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) {
205205

206206
POINT pt = pmouse->pt;
207207
HWND hwnd = WindowFromPoint(pt);
208-
NodePtr top_container_view = GetTopContainerView(
209-
GetFocus()); // Must use `GetFocus()`, otherwise when opening bookmarks
210-
// in a bookmark folder (and similar expanded menus),
211-
// `top_container_view` cannot be obtained, making it
212-
// impossible to correctly determine `is_on_new_tab`. See
213-
// #98.
214208

215-
bool is_on_bookmark = IsOnBookmark(hwnd, pt);
216-
bool is_on_expanded_list = IsOnExpandedList(hwnd, pt);
217-
if (is_on_bookmark && is_on_expanded_list) {
209+
if (!IsOnBookmark(hwnd, pt)) {
210+
return false;
211+
}
212+
213+
if (IsOnExpandedList(hwnd, pt)) {
218214
// This is only used to determine the expanded dropdown menu of the address
219215
// bar. When the mouse clicks on it, it may penetrate through to the
220216
// background, causing a misjudgment that it is on the bookmark. Related
221217
// issue: https://github.com/Bush2021/chrome_plus/issues/162
222218
return false;
223219
}
224220

225-
bool is_on_new_tab = IsOnNewTab(top_container_view);
226-
if (is_on_bookmark && !is_on_new_tab) {
221+
NodePtr top_container_view = GetTopContainerView(
222+
GetFocus()); // Must use `GetFocus()`, otherwise when opening bookmarks
223+
// in a bookmark folder (and similar expanded menus),
224+
// `top_container_view` cannot be obtained, making it
225+
// impossible to correctly determine `is_on_new_tab`. See
226+
// #98.
227+
228+
if (!IsOnNewTab(top_container_view)) {
227229
if (mode == 1) {
228230
SendKey(VK_MBUTTON, VK_SHIFT);
229231
} else if (mode == 2) {
230232
SendKey(VK_MBUTTON);
231233
}
232234
return true;
233235
}
234-
235236
return false;
236237
}
237238

0 commit comments

Comments
 (0)