Skip to content

Sprinkle #[inline] across the library #1318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5db106
deserialize: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
4fc0c26
serialize: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
13b05c6
frame/request: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
0f2827a
frame/response: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
c0d7601
frame: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
b840930
value: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
760d5f4
session: merge `Session`'s `impl` blocks
wprzytula Apr 12, 2025
da27942
session: sprinkle `#[inline]` onto short API fns
wprzytula Apr 12, 2025
ce41efc
session_builder: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
fbc91fb
node: sprinkle `#[inline]` onto short API fns
wprzytula Apr 12, 2025
531e7c8
cluster/state: sprinkle `#[inline]` onto short API fns
wprzytula Apr 12, 2025
4d4e4bf
statements: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
2c9c98f
prepared_statement: add missing docstrings
wprzytula Apr 12, 2025
b36cbd7
locator: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
9393e05
self_identity: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
f4e5d4c
caching_session: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
43b2db8
execution_profile: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
7dc2124
metrics: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
fdabd17
retry_policy: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
f85b65a
host_filter: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
7c71501
speculative_execution: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
71380c1
timestamp_generator: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
5ff333a
sharding: sprinkle `#[inline]` onto pub fns
wprzytula Apr 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scylla-cql/src/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ impl TypeCheckError {
}

/// Retrieve an error reason by downcasting to specific type.
#[inline]
pub fn downcast_ref<T: std::error::Error + 'static>(&self) -> Option<&T> {
self.0.downcast_ref()
}
Expand Down Expand Up @@ -284,6 +285,7 @@ impl DeserializationError {
}

/// Retrieve an error reason by downcasting to specific type.
#[inline]
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
self.0.downcast_ref()
}
Expand Down
2 changes: 2 additions & 0 deletions scylla-cql/src/deserialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ pub struct BuiltinTypeCheckError {

// Not part of the public API; used in derive macros.
#[doc(hidden)]
#[inline]
pub fn mk_typck_err<T>(
cql_types: impl IntoIterator<Item = ColumnType<'static>>,
kind: impl Into<BuiltinTypeCheckErrorKind>,
Expand Down Expand Up @@ -423,6 +424,7 @@ pub struct BuiltinDeserializationError {

// Not part of the public API; used in derive macros.
#[doc(hidden)]
#[inline]
pub fn mk_deser_err<T>(kind: impl Into<BuiltinDeserializationErrorKind>) -> DeserializationError {
mk_deser_err_named(std::any::type_name::<T>(), kind)
}
Expand Down
7 changes: 7 additions & 0 deletions scylla-cql/src/deserialize/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ where
Some(do_next())
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.raw_iter.size_hint()
}
Expand Down Expand Up @@ -1310,6 +1311,7 @@ impl<'frame, 'metadata> Iterator for UdtIterator<'frame, 'metadata> {
Some((head, raw_res))
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.raw_iter.size_hint()
}
Expand Down Expand Up @@ -1403,6 +1405,7 @@ impl<'frame> FixedLengthBytesSequenceIterator<'frame> {
impl<'frame> Iterator for FixedLengthBytesSequenceIterator<'frame> {
type Item = Result<Option<FrameSlice<'frame>>, LowLevelDeserializationError>;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.remaining = self.remaining.checked_sub(1)?;
Some(self.slice.read_cql_bytes())
Expand Down Expand Up @@ -1433,6 +1436,7 @@ impl<'frame> From<FrameSlice<'frame>> for BytesSequenceIterator<'frame> {
impl<'frame> Iterator for BytesSequenceIterator<'frame> {
type Item = Result<Option<FrameSlice<'frame>>, LowLevelDeserializationError>;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.slice.as_slice().is_empty() {
None
Expand Down Expand Up @@ -1946,6 +1950,7 @@ impl Display for MapDeserializationErrorKind {
}

impl From<MapDeserializationErrorKind> for BuiltinDeserializationErrorKind {
#[inline]
fn from(err: MapDeserializationErrorKind) -> Self {
Self::MapError(err)
}
Expand Down Expand Up @@ -1979,6 +1984,7 @@ impl Display for TupleDeserializationErrorKind {
}

impl From<TupleDeserializationErrorKind> for BuiltinDeserializationErrorKind {
#[inline]
fn from(err: TupleDeserializationErrorKind) -> Self {
Self::TupleError(err)
}
Expand Down Expand Up @@ -2009,6 +2015,7 @@ impl Display for UdtDeserializationErrorKind {
}

impl From<UdtDeserializationErrorKind> for BuiltinDeserializationErrorKind {
#[inline]
fn from(err: UdtDeserializationErrorKind) -> Self {
Self::UdtError(err)
}
Expand Down
2 changes: 2 additions & 0 deletions scylla-cql/src/frame/frame_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub enum CqlResponseParseError {
}

impl CqlResponseParseError {
#[inline]
pub fn to_response_kind(&self) -> CqlResponseKind {
match self {
CqlResponseParseError::CqlErrorParseError(_) => CqlResponseKind::Error,
Expand Down Expand Up @@ -486,6 +487,7 @@ pub enum LowLevelDeserializationError {
}

impl From<std::io::Error> for LowLevelDeserializationError {
#[inline]
fn from(value: std::io::Error) -> Self {
Self::IoError(Arc::new(value))
}
Expand Down
5 changes: 5 additions & 0 deletions scylla-cql/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum Compression {
}

impl Compression {
#[inline]
pub fn as_str(&self) -> &'static str {
match self {
Compression::Lz4 => "lz4",
Expand All @@ -57,6 +58,7 @@ impl Compression {
}

impl Display for Compression {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
Expand Down Expand Up @@ -98,10 +100,12 @@ impl SerializedRequest {
Ok(Self { data })
}

#[inline]
pub fn set_stream(&mut self, stream: i16) {
self.data[2..4].copy_from_slice(&stream.to_be_bytes());
}

#[inline]
pub fn get_data(&self) -> &[u8] {
&self.data[..]
}
Expand All @@ -116,6 +120,7 @@ pub struct FrameParams {
}

impl Default for FrameParams {
#[inline]
fn default() -> Self {
Self {
version: 0x04,
Expand Down
1 change: 1 addition & 0 deletions scylla-cql/src/frame/protocol_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl ProtocolFeatures {
}
}

#[inline]
pub fn prepared_flags_contain_lwt_mark(&self, flags: u32) -> bool {
self.lwt_optimization_meta_bit_mask
.map(|mask| (flags & mask) == mask)
Expand Down
1 change: 1 addition & 0 deletions scylla-cql/src/frame/request/auth_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct AuthResponse {
impl SerializableRequest for AuthResponse {
const OPCODE: RequestOpcode = RequestOpcode::AuthResponse;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
Ok(write_bytes_opt(self.response.as_ref(), buf)
.map_err(AuthResponseSerializationError::ResponseSerialization)?)
Expand Down
3 changes: 3 additions & 0 deletions scylla-cql/src/frame/request/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct BatchTypeParseError {
impl TryFrom<u8> for BatchType {
type Error = BatchTypeParseError;

#[inline]
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::Logged),
Expand Down Expand Up @@ -182,6 +183,7 @@ where
{
const OPCODE: RequestOpcode = RequestOpcode::Batch;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
self.do_serialize(buf)?;
Ok(())
Expand Down Expand Up @@ -230,6 +232,7 @@ impl BatchStatement<'_> {
// Can be removed once https://github.com/rust-lang/rust-clippy/issues/12495 is fixed.
#[allow(clippy::needless_lifetimes)]
impl<'s, 'b> From<&'s BatchStatement<'b>> for BatchStatement<'s> {
#[inline]
fn from(value: &'s BatchStatement) -> Self {
match value {
BatchStatement::Query { text } => BatchStatement::Query { text: text.clone() },
Expand Down
2 changes: 2 additions & 0 deletions scylla-cql/src/frame/request/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Execute<'a> {
impl SerializableRequest for Execute<'_> {
const OPCODE: RequestOpcode = RequestOpcode::Execute;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
// Serializing statement id
types::write_short_bytes(&self.id[..], buf)
Expand All @@ -37,6 +38,7 @@ impl SerializableRequest for Execute<'_> {
}

impl DeserializableRequest for Execute<'_> {
#[inline]
fn deserialize(buf: &mut &[u8]) -> Result<Self, RequestDeserializationError> {
let id = types::read_short_bytes(buf)?.to_vec().into();
let parameters = QueryParameters::deserialize(buf)?;
Expand Down
4 changes: 4 additions & 0 deletions scylla-cql/src/frame/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum RequestOpcode {
impl TryFrom<u8> for RequestOpcode {
type Error = TryFromPrimitiveError<u8>;

#[inline]
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0x01 => Ok(Self::Startup),
Expand All @@ -98,6 +99,7 @@ pub trait SerializableRequest {

fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError>;

#[inline]
fn to_bytes(&self) -> Result<Bytes, CqlRequestSerializationError> {
let mut v = Vec::new();
self.serialize(&mut v)?;
Expand Down Expand Up @@ -157,6 +159,7 @@ impl Request<'_> {
}

/// Retrieves consistency from request frame, if present.
#[inline]
pub fn get_consistency(&self) -> Option<Consistency> {
match self {
Request::Query(q) => Some(q.parameters.consistency),
Expand All @@ -168,6 +171,7 @@ impl Request<'_> {
}

/// Retrieves serial consistency from request frame.
#[inline]
pub fn get_serial_consistency(&self) -> Option<Option<SerialConsistency>> {
match self {
Request::Query(q) => Some(q.parameters.serial_consistency),
Expand Down
1 change: 1 addition & 0 deletions scylla-cql/src/frame/request/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Options;
impl SerializableRequest for Options {
const OPCODE: RequestOpcode = RequestOpcode::Options;

#[inline]
fn serialize(&self, _buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions scylla-cql/src/frame/request/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Prepare<'a> {
impl SerializableRequest for Prepare<'_> {
const OPCODE: RequestOpcode = RequestOpcode::Prepare;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
types::write_long_string(self.query, buf)
.map_err(PrepareSerializationError::StatementStringSerialization)?;
Expand Down
4 changes: 4 additions & 0 deletions scylla-cql/src/frame/request/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct Query<'q> {
impl SerializableRequest for Query<'_> {
const OPCODE: RequestOpcode = RequestOpcode::Query;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
types::write_long_string(&self.contents, buf)
.map_err(QuerySerializationError::StatementStringSerialization)?;
Expand All @@ -48,6 +49,7 @@ impl SerializableRequest for Query<'_> {
}

impl DeserializableRequest for Query<'_> {
#[inline]
fn deserialize(buf: &mut &[u8]) -> Result<Self, RequestDeserializationError> {
let contents = Cow::Owned(types::read_long_string(buf)?.to_owned());
let parameters = QueryParameters::deserialize(buf)?;
Expand All @@ -71,6 +73,7 @@ pub struct QueryParameters<'a> {
}

impl Default for QueryParameters<'_> {
#[inline]
fn default() -> Self {
Self {
consistency: Default::default(),
Expand Down Expand Up @@ -279,6 +282,7 @@ impl PagingState {
}

impl Default for PagingState {
#[inline]
fn default() -> Self {
Self::start()
}
Expand Down
1 change: 1 addition & 0 deletions scylla-cql/src/frame/request/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Register {
impl SerializableRequest for Register {
const OPCODE: RequestOpcode = RequestOpcode::Register;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
let event_types_list = self
.event_types_to_register_for
Expand Down
1 change: 1 addition & 0 deletions scylla-cql/src/frame/request/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Startup<'a> {
impl SerializableRequest for Startup<'_> {
const OPCODE: RequestOpcode = RequestOpcode::Startup;

#[inline]
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
types::write_string_map(&self.options, buf)
.map_err(StartupSerializationError::OptionsSerialization)?;
Expand Down
3 changes: 3 additions & 0 deletions scylla-cql/src/frame/response/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Authenticate {
}

impl Authenticate {
#[inline]
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthenticateParseError> {
let authenticator_name = types::read_string(buf)
.map_err(CqlAuthenticateParseError::AuthNameParseError)?
Expand All @@ -25,6 +26,7 @@ pub struct AuthSuccess {
}

impl AuthSuccess {
#[inline]
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthSuccessParseError> {
let success_message = types::read_bytes_opt(buf)
.map_err(CqlAuthSuccessParseError::SuccessMessageParseError)?
Expand All @@ -40,6 +42,7 @@ pub struct AuthChallenge {
}

impl AuthChallenge {
#[inline]
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthChallengeParseError> {
let authenticate_message = types::read_bytes_opt(buf)
.map_err(CqlAuthChallengeParseError::AuthMessageParseError)?
Expand Down
6 changes: 5 additions & 1 deletion scylla-cql/src/frame/response/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,14 @@ pub enum WriteType {
}

impl std::fmt::Display for WriteType {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
<Self as std::fmt::Debug>::fmt(self, f)
}
}

impl From<u8> for OperationType {
#[inline]
fn from(operation_type: u8) -> OperationType {
match operation_type {
0 => OperationType::Read,
Expand All @@ -479,6 +481,7 @@ impl From<u8> for OperationType {
}

impl From<&str> for WriteType {
#[inline]
fn from(write_type_str: &str) -> WriteType {
match write_type_str {
"SIMPLE" => WriteType::Simple,
Expand All @@ -495,6 +498,7 @@ impl From<&str> for WriteType {
}

impl WriteType {
#[inline]
pub fn as_str(&self) -> &str {
match self {
WriteType::Simple => "SIMPLE",
Expand Down
4 changes: 4 additions & 0 deletions scylla-cql/src/frame/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub enum ResponseOpcode {
impl TryFrom<u8> for ResponseOpcode {
type Error = TryFromPrimitiveError<u8>;

#[inline]
fn try_from(value: u8) -> Result<Self, TryFromPrimitiveError<u8>> {
match value {
0x00 => Ok(Self::Error),
Expand Down Expand Up @@ -93,6 +94,7 @@ pub enum Response {
}

impl Response {
#[inline]
pub fn to_response_kind(&self) -> CqlResponseKind {
match self {
Response::Error(_) => CqlResponseKind::Error,
Expand Down Expand Up @@ -135,6 +137,7 @@ impl Response {
Ok(response)
}

#[inline]
pub fn into_non_error_response(self) -> Result<NonErrorResponse, error::Error> {
let non_error_response = match self {
Response::Error(e) => return Err(e),
Expand Down Expand Up @@ -164,6 +167,7 @@ pub enum NonErrorResponse {
}

impl NonErrorResponse {
#[inline]
pub fn to_response_kind(&self) -> CqlResponseKind {
match self {
NonErrorResponse::Ready => CqlResponseKind::Ready,
Expand Down
Loading