Commit 91165cea authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Devirtualize calls made on a mojo::InterfacePtr<T>

This patch devirtualizes calls to interface methods made through a
mojo::InterfacePtr<T> and mojo::AssociatedInterfacePtr<T> by making
get() and the -> and . operators return the proxy type directly and
marking the interface methods on the proxy as final.

The motivation of this change is performance and binary size. The non-
virtual call sites are slightly smaller but not enough to effect the
complete binary. Performance should be net-positive but as yet has not
been accurately measured.

Bug: None
Change-Id: I463bc32c1989853606d118f57ded5c9dd9f34e2f
Reviewed-on: https://chromium-review.googlesource.com/747884
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarYuzhu Shen <yzshen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513030}
parent fc2679df
......@@ -32,6 +32,7 @@ class AssociatedInterfacePtr {
public:
using InterfaceType = Interface;
using PtrInfoType = AssociatedInterfacePtrInfo<Interface>;
using Proxy = typename Interface::Proxy_;
// Constructs an unbound AssociatedInterfacePtr.
AssociatedInterfacePtr() {}
......@@ -79,11 +80,11 @@ class AssociatedInterfacePtr {
bool is_bound() const { return internal_state_.is_bound(); }
Interface* get() const { return internal_state_.instance(); }
Proxy* get() const { return internal_state_.instance(); }
// Functions like a pointer to Interface. Must already be bound.
Interface* operator->() const { return get(); }
Interface& operator*() const { return *get(); }
Proxy* operator->() const { return get(); }
Proxy& operator*() const { return *get(); }
// Returns the version number of the interface that the remote side supports.
uint32_t version() const { return internal_state_.version(); }
......
......@@ -39,6 +39,7 @@ class InterfacePtr {
public:
using InterfaceType = Interface;
using PtrInfoType = InterfacePtrInfo<Interface>;
using Proxy = typename Interface::Proxy_;
// Constructs an unbound InterfacePtr.
InterfacePtr() {}
......@@ -89,11 +90,11 @@ class InterfacePtr {
// Returns a raw pointer to the local proxy. Caller does not take ownership.
// Note that the local proxy is thread hostile, as stated above.
Interface* get() const { return internal_state_.instance(); }
Proxy* get() const { return internal_state_.instance(); }
// Functions like a pointer to Interface. Must already be bound.
Interface* operator->() const { return get(); }
Interface& operator*() const { return *get(); }
Proxy* operator->() const { return get(); }
Proxy& operator*() const { return *get(); }
// Returns the version number of the interface that the remote side supports.
uint32_t version() const { return internal_state_.version(); }
......
......@@ -97,10 +97,12 @@ class MOJO_CPP_BINDINGS_EXPORT AssociatedInterfacePtrStateBase {
template <typename Interface>
class AssociatedInterfacePtrState : public AssociatedInterfacePtrStateBase {
public:
using Proxy = typename Interface::Proxy_;
AssociatedInterfacePtrState() {}
~AssociatedInterfacePtrState() = default;
Interface* instance() {
Proxy* instance() {
// This will be null if the object is not bound.
return proxy_.get();
}
......@@ -129,8 +131,6 @@ class AssociatedInterfacePtrState : public AssociatedInterfacePtrStateBase {
}
private:
using Proxy = typename Interface::Proxy_;
std::unique_ptr<Proxy> proxy_;
DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState);
......
......@@ -104,10 +104,12 @@ class MOJO_CPP_BINDINGS_EXPORT InterfacePtrStateBase {
template <typename Interface>
class InterfacePtrState : public InterfacePtrStateBase {
public:
using Proxy = typename Interface::Proxy_;
InterfacePtrState() = default;
~InterfacePtrState() = default;
Interface* instance() {
Proxy* instance() {
ConfigureProxyIfNecessary();
// This will be null if the object is not bound.
......@@ -192,8 +194,6 @@ class InterfacePtrState : public InterfacePtrStateBase {
}
private:
using Proxy = typename Interface::Proxy_;
void ConfigureProxyIfNecessary() {
// The proxy has been configured.
if (proxy_) {
......
......@@ -6,9 +6,9 @@ class {{export_attribute}} {{interface.name}}Proxy
{%- for method in interface.methods %}
{%- if method.sync %}
bool {{method.name}}({{interface_macros.declare_sync_method_params("", method)}}) override;
bool {{method.name}}({{interface_macros.declare_sync_method_params("", method)}}) final;
{%- endif %}
void {{method.name}}({{interface_macros.declare_request_params("", method, use_once_callback)}}) override;
void {{method.name}}({{interface_macros.declare_request_params("", method, use_once_callback)}}) final;
{%- endfor %}
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment