refactor: instantiate navigation_entries local variable on the stack (#46504)

* refactor: instantiate navigation_entries on the stack instead of the heap

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: reserve the full size of navigation_entries

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use emplace_back to simplify the code a little

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-04-05 10:45:02 -05:00 committed by GitHub
parent 42514326ca
commit 31e3c84843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2518,8 +2518,9 @@ void WebContents::RestoreHistory(
return;
}
auto navigation_entries = std::make_unique<
std::vector<std::unique_ptr<content::NavigationEntry>>>();
auto navigation_entries =
std::vector<std::unique_ptr<content::NavigationEntry>>{};
navigation_entries.reserve(entries.size());
blink::UserAgentOverride ua_override;
ua_override.ua_string_override = GetUserAgent();
@ -2539,14 +2540,13 @@ void WebContents::RestoreHistory(
nav_entry->SetIsOverridingUserAgent(
!ua_override.ua_string_override.empty());
navigation_entries->push_back(
std::unique_ptr<content::NavigationEntry>(nav_entry));
navigation_entries.emplace_back(nav_entry);
}
if (!navigation_entries->empty()) {
if (!navigation_entries.empty()) {
web_contents()->SetUserAgentOverride(ua_override, false);
web_contents()->GetController().Restore(
index, content::RestoreType::kRestored, navigation_entries.get());
index, content::RestoreType::kRestored, &navigation_entries);
web_contents()->GetController().LoadIfNecessary();
}
}