Skip to content

Commit

Permalink
Inline ZenohMessage::make_data() and other functions (perf)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Mar 15, 2021
1 parent c2cb54f commit 1bd022e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions zenoh/src/net/protocol/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ pub enum ResKey {
use ResKey::*;

impl ResKey {
#[inline(always)]
pub fn rid(&self) -> ResourceId {
match self {
RName(_) => NO_RESOURCE_ID,
RId(rid) | RIdWithSuffix(rid, _) => *rid,
}
}

#[inline(always)]
pub fn is_numerical(&self) -> bool {
matches!(self, RId(_))
}
Expand All @@ -104,24 +106,28 @@ impl fmt::Display for ResKey {
}

impl From<ResourceId> for ResKey {
#[inline]
fn from(rid: ResourceId) -> ResKey {
RId(rid)
}
}

impl From<&str> for ResKey {
#[inline]
fn from(name: &str) -> ResKey {
RName(name.to_string())
}
}

impl From<String> for ResKey {
#[inline]
fn from(name: String) -> ResKey {
RName(name)
}
}

impl From<(ResourceId, &str)> for ResKey {
#[inline]
fn from(tuple: (ResourceId, &str)) -> ResKey {
if tuple.1.is_empty() {
RId(tuple.0)
Expand All @@ -134,6 +140,7 @@ impl From<(ResourceId, &str)> for ResKey {
}

impl From<(ResourceId, String)> for ResKey {
#[inline]
fn from(tuple: (ResourceId, String)) -> ResKey {
if tuple.1.is_empty() {
RId(tuple.0)
Expand All @@ -146,6 +153,7 @@ impl From<(ResourceId, String)> for ResKey {
}

impl<'a> From<&'a ResKey> for (ResourceId, &'a str) {
#[inline]
fn from(key: &'a ResKey) -> (ResourceId, &'a str) {
match key {
RId(rid) => (*rid, ""),
Expand Down
2 changes: 2 additions & 0 deletions zenoh/src/net/protocol/proto/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ impl ZenohMessage {
}

#[allow(clippy::too_many_arguments)]
#[inline(always)]
pub fn make_data(
key: ResKey,
payload: RBuf,
Expand Down Expand Up @@ -706,6 +707,7 @@ impl ZenohMessage {
}
}

#[inline(always)]
pub fn make_query(
key: ResKey,
predicate: String,
Expand Down

0 comments on commit 1bd022e

Please sign in to comment.