Annotate all simple getters with #[inline].

This commit is contained in:
whitequark 2017-07-04 18:46:36 +00:00
parent 3f9805b2c1
commit 5556f09351
3 changed files with 17 additions and 0 deletions

View File

@ -70,6 +70,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
} }
/// Return the debug identifier. /// Return the debug identifier.
#[inline]
pub fn debug_id(&self) -> usize { pub fn debug_id(&self) -> usize {
self.debug_id self.debug_id
} }
@ -83,21 +84,25 @@ impl<'a, 'b> RawSocket<'a, 'b> {
} }
/// Return the IP version the socket is bound to. /// Return the IP version the socket is bound to.
#[inline]
pub fn ip_version(&self) -> IpVersion { pub fn ip_version(&self) -> IpVersion {
self.ip_version self.ip_version
} }
/// Return the IP protocol the socket is bound to. /// Return the IP protocol the socket is bound to.
#[inline]
pub fn ip_protocol(&self) -> IpProtocol { pub fn ip_protocol(&self) -> IpProtocol {
self.ip_protocol self.ip_protocol
} }
/// Check whether the transmit buffer is full. /// Check whether the transmit buffer is full.
#[inline]
pub fn can_send(&self) -> bool { pub fn can_send(&self) -> bool {
!self.tx_buffer.full() !self.tx_buffer.full()
} }
/// Check whether the receive buffer is not empty. /// Check whether the receive buffer is not empty.
#[inline]
pub fn can_recv(&self) -> bool { pub fn can_recv(&self) -> bool {
!self.rx_buffer.empty() !self.rx_buffer.empty()
} }

View File

@ -298,6 +298,7 @@ impl<'a> TcpSocket<'a> {
} }
/// Return the debug identifier. /// Return the debug identifier.
#[inline]
pub fn debug_id(&self) -> usize { pub fn debug_id(&self) -> usize {
self.debug_id self.debug_id
} }
@ -323,6 +324,7 @@ impl<'a> TcpSocket<'a> {
} }
/// Return the connection state, in terms of the TCP state machine. /// Return the connection state, in terms of the TCP state machine.
#[inline]
pub fn state(&self) -> State { pub fn state(&self) -> State {
self.state self.state
} }
@ -444,6 +446,7 @@ impl<'a> TcpSocket<'a> {
/// Return whether the socket is passively listening for incoming connections. /// Return whether the socket is passively listening for incoming connections.
/// ///
/// In terms of the TCP state machine, the socket must be in the `LISTEN` state. /// In terms of the TCP state machine, the socket must be in the `LISTEN` state.
#[inline]
pub fn is_listening(&self) -> bool { pub fn is_listening(&self) -> bool {
match self.state { match self.state {
State::Listen => true, State::Listen => true,
@ -458,6 +461,7 @@ impl<'a> TcpSocket<'a> {
/// the socket; for that, use [can_send](#method.can_send) or [can_recv](#method.can_recv). /// the socket; for that, use [can_send](#method.can_send) or [can_recv](#method.can_recv).
/// ///
/// In terms of the TCP state machine, the socket must be in the `CLOSED` or `TIME-WAIT` state. /// In terms of the TCP state machine, the socket must be in the `CLOSED` or `TIME-WAIT` state.
#[inline]
pub fn is_open(&self) -> bool { pub fn is_open(&self) -> bool {
match self.state { match self.state {
State::Closed => false, State::Closed => false,
@ -478,6 +482,7 @@ impl<'a> TcpSocket<'a> {
/// ///
/// In terms of the TCP state machine, the socket must be in the `CLOSED`, `TIME-WAIT`, /// In terms of the TCP state machine, the socket must be in the `CLOSED`, `TIME-WAIT`,
/// or `LISTEN` state. /// or `LISTEN` state.
#[inline]
pub fn is_active(&self) -> bool { pub fn is_active(&self) -> bool {
match self.state { match self.state {
State::Closed => false, State::Closed => false,
@ -496,6 +501,7 @@ impl<'a> TcpSocket<'a> {
/// ///
/// In terms of the TCP state machine, the socket must be in the `ESTABLISHED` or /// In terms of the TCP state machine, the socket must be in the `ESTABLISHED` or
/// `CLOSE-WAIT` state. /// `CLOSE-WAIT` state.
#[inline]
pub fn may_send(&self) -> bool { pub fn may_send(&self) -> bool {
match self.state { match self.state {
State::Established => true, State::Established => true,
@ -514,6 +520,7 @@ impl<'a> TcpSocket<'a> {
/// ///
/// In terms of the TCP state machine, the socket must be in the `ESTABLISHED`, /// In terms of the TCP state machine, the socket must be in the `ESTABLISHED`,
/// `FIN-WAIT-1`, or `FIN-WAIT-2` state, or have data in the receive buffer instead. /// `FIN-WAIT-1`, or `FIN-WAIT-2` state, or have data in the receive buffer instead.
#[inline]
pub fn may_recv(&self) -> bool { pub fn may_recv(&self) -> bool {
match self.state { match self.state {
State::Established => true, State::Established => true,
@ -528,6 +535,7 @@ impl<'a> TcpSocket<'a> {
/// Check whether the transmit half of the full-duplex connection is open /// Check whether the transmit half of the full-duplex connection is open
/// (see [may_send](#method.may_send), and the transmit buffer is not full. /// (see [may_send](#method.may_send), and the transmit buffer is not full.
#[inline]
pub fn can_send(&self) -> bool { pub fn can_send(&self) -> bool {
if !self.may_send() { return false } if !self.may_send() { return false }
@ -536,6 +544,7 @@ impl<'a> TcpSocket<'a> {
/// Check whether the receive half of the full-duplex connection buffer is open /// Check whether the receive half of the full-duplex connection buffer is open
/// (see [may_recv](#method.may_recv), and the receive buffer is not empty. /// (see [may_recv](#method.may_recv), and the receive buffer is not empty.
#[inline]
pub fn can_recv(&self) -> bool { pub fn can_recv(&self) -> bool {
if !self.may_recv() { return false } if !self.may_recv() { return false }

View File

@ -70,6 +70,7 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
} }
/// Return the debug identifier. /// Return the debug identifier.
#[inline]
pub fn debug_id(&self) -> usize { pub fn debug_id(&self) -> usize {
self.debug_id self.debug_id
} }
@ -94,11 +95,13 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
} }
/// Check whether the transmit buffer is full. /// Check whether the transmit buffer is full.
#[inline]
pub fn can_send(&self) -> bool { pub fn can_send(&self) -> bool {
!self.tx_buffer.full() !self.tx_buffer.full()
} }
/// Check whether the receive buffer is not empty. /// Check whether the receive buffer is not empty.
#[inline]
pub fn can_recv(&self) -> bool { pub fn can_recv(&self) -> bool {
!self.rx_buffer.empty() !self.rx_buffer.empty()
} }