perf: avoid redundant calls to GetView() (#43231)

* perf: avoid double-calls to GetView()

There are a lot of places where we call the virtual method GetView()
twice in succession: the first to check if the view exists, and the
second to use. This PR holds the view in a temp variable instead, e.g.:

if (auto* view = foo->GetView())
  view->DoSomething();

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

* perf: avoid discarded GetView() call

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] 2024-08-06 19:24:05 -05:00 committed by GitHub
parent 22b66ee6de
commit 31e6d66c74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 28 deletions

View file

@ -565,10 +565,8 @@ OffScreenRenderWidgetHostView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host,
content::RenderWidgetHost* embedder_render_widget_host,
content::WebContentsView* web_contents_view) {
if (render_widget_host->GetView()) {
return static_cast<content::RenderWidgetHostViewBase*>(
render_widget_host->GetView());
}
if (auto* rwhv = render_widget_host->GetView())
return static_cast<content::RenderWidgetHostViewBase*>(rwhv);
OffScreenRenderWidgetHostView* embedder_host_view = nullptr;
if (embedder_render_widget_host) {