Skip to content

Commit

Permalink
feat: speed up message bus matching (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 3, 2022
1 parent 3d32552 commit cccfea3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
39 changes: 20 additions & 19 deletions src/dbus_fast/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,11 +773,11 @@ def _process_message(self, msg: Message) -> None:
break

if msg.message_type == MessageType.SIGNAL:
if msg._matches(
member="NameOwnerChanged", # least likely to match
sender="org.freedesktop.DBus",
path="/org/freedesktop/DBus",
interface="org.freedesktop.DBus",
if (
msg.member == "NameOwnerChanged"
and msg.sender == "org.freedesktop.DBus"
and msg.path == "/org/freedesktop/DBus"
and msg.interface == "org.freedesktop.DBus"
):
[name, old_owner, new_owner] = msg.body
if new_owner:
Expand Down Expand Up @@ -827,23 +827,24 @@ def _find_message_handler(
) -> Optional[Callable[[Message, Callable], None]]:
handler = None

if msg._matches(
interface="org.freedesktop.DBus.Introspectable",
member="Introspect",
signature="",
if (
msg.interface == "org.freedesktop.DBus.Introspectable"
and msg.member == "Introspect"
and msg.signature == ""
):
handler = self._default_introspect_handler

elif msg._matches(interface="org.freedesktop.DBus.Properties"):
elif msg.interface == "org.freedesktop.DBus.Properties":
handler = self._default_properties_handler

elif msg._matches(interface="org.freedesktop.DBus.Peer"):
if msg._matches(member="Ping", signature=""):
elif msg.interface == "org.freedesktop.DBus.Peer":
if msg.member == "Ping" and msg.signature == "":
handler = self._default_ping_handler
elif msg._matches(member="GetMachineId", signature=""):
elif msg.member == "GetMachineId" and msg.signature == "":
handler = self._default_get_machine_id_handler
elif msg._matches(
interface="org.freedesktop.DBus.ObjectManager", member="GetManagedObjects"
elif (
msg.interface == "org.freedesktop.DBus.ObjectManager"
and msg.member == "GetManagedObjects"
):
handler = self._default_get_managed_objects_handler

Expand All @@ -852,10 +853,10 @@ def _find_message_handler(
for method in ServiceInterface._get_methods(interface):
if method.disabled:
continue
if msg._matches(
interface=interface.name,
member=method.name,
signature=method.in_signature,
if (
msg.interface == interface.name
and msg.member == method.name
and msg.signature == method.in_signature
):
handler = self._make_method_handler(interface, method)
break
Expand Down
8 changes: 3 additions & 5 deletions src/dbus_fast/proxy_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ def _add_property(self, intr_property: intr.Property) -> None:

def _message_handler(self, msg: Message) -> None:
if (
not msg._matches(
message_type=MessageType.SIGNAL,
interface=self.introspection.name,
path=self.path,
)
msg.message_type != MessageType.SIGNAL
or msg.interface != self.introspection.name
or msg.path != self.path
or msg.member not in self._signal_handlers
):
return
Expand Down

0 comments on commit cccfea3

Please sign in to comment.