Skip to content

Commit

Permalink
Remove manual #[inline] attributes (#2702)
Browse files Browse the repository at this point in the history
The compiler knows best as inlining is quite complicated. This should
help with compile times, significantly.
  • Loading branch information
GnomedDev committed Mar 11, 2024
1 parent b391078 commit 820a91a
Show file tree
Hide file tree
Showing 50 changed files with 0 additions and 449 deletions.
11 changes: 0 additions & 11 deletions command_attr/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub struct Values {
}

impl Values {
#[inline]
pub fn new(name: Ident, kind: ValueKind, literals: Vec<Lit>, span: Span) -> Self {
Values {
name,
Expand Down Expand Up @@ -140,7 +139,6 @@ impl<'a, T: fmt::Display> fmt::Display for DisplaySlice<'a, T> {
}
}

#[inline]
fn is_form_acceptable(expect: &[ValueKind], kind: ValueKind) -> bool {
if expect.contains(&ValueKind::List) && kind == ValueKind::SingleList {
true
Expand All @@ -149,7 +147,6 @@ fn is_form_acceptable(expect: &[ValueKind], kind: ValueKind) -> bool {
}
}

#[inline]
fn validate(values: &Values, forms: &[ValueKind]) -> Result<()> {
if !is_form_acceptable(forms, values.kind) {
return Err(Error::new(
Expand All @@ -162,7 +159,6 @@ fn validate(values: &Values, forms: &[ValueKind]) -> Result<()> {
Ok(())
}

#[inline]
pub fn parse<T: AttributeOption>(values: Values) -> Result<T> {
T::parse(values)
}
Expand All @@ -180,7 +176,6 @@ impl AttributeOption for Vec<String> {
}

impl AttributeOption for String {
#[inline]
fn parse(values: Values) -> Result<Self> {
validate(&values, &[ValueKind::Equals, ValueKind::SingleList])?;

Expand All @@ -189,7 +184,6 @@ impl AttributeOption for String {
}

impl AttributeOption for bool {
#[inline]
fn parse(values: Values) -> Result<Self> {
validate(&values, &[ValueKind::Name, ValueKind::SingleList])?;

Expand All @@ -198,7 +192,6 @@ impl AttributeOption for bool {
}

impl AttributeOption for Ident {
#[inline]
fn parse(values: Values) -> Result<Self> {
validate(&values, &[ValueKind::SingleList])?;

Expand All @@ -207,7 +200,6 @@ impl AttributeOption for Ident {
}

impl AttributeOption for Vec<Ident> {
#[inline]
fn parse(values: Values) -> Result<Self> {
validate(&values, &[ValueKind::List])?;

Expand Down Expand Up @@ -254,7 +246,6 @@ impl AttributeOption for HelpBehaviour {
}

impl AttributeOption for Checks {
#[inline]
fn parse(values: Values) -> Result<Self> {
<Vec<Ident> as AttributeOption>::parse(values).map(Checks)
}
Expand All @@ -279,7 +270,6 @@ impl AttributeOption for Permissions {
}

impl<T: AttributeOption> AttributeOption for AsOption<T> {
#[inline]
fn parse(values: Values) -> Result<Self> {
Ok(AsOption(Some(T::parse(values)?)))
}
Expand Down Expand Up @@ -308,7 +298,6 @@ macro_rules! attr_option_num {
}

impl AttributeOption for Option<$n> {
#[inline]
fn parse(values: Values) -> Result<Self> {
<$n as AttributeOption>::parse(values).map(Some)
}
Expand Down
3 changes: 0 additions & 3 deletions command_attr/src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub enum OnlyIn {
}

impl OnlyIn {
#[inline]
pub fn from_str(s: &str, span: Span) -> Result<Self> {
match s {
"guilds" | "guild" => Ok(OnlyIn::Guild),
Expand Down Expand Up @@ -461,7 +460,6 @@ pub struct Options {
}

impl Options {
#[inline]
pub fn new() -> Self {
Self {
help_available: true,
Expand Down Expand Up @@ -635,7 +633,6 @@ pub struct GroupOptions {
}

impl GroupOptions {
#[inline]
pub fn new() -> Self {
Self {
help_available: true,
Expand Down
10 changes: 0 additions & 10 deletions command_attr/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl LitExt for Lit {
}
}

#[inline]
fn to_ident(&self) -> Ident {
Ident::new(&self.to_str(), self.span())
}
Expand All @@ -59,25 +58,21 @@ pub trait IdentExt2: Sized {
}

impl IdentExt2 for Ident {
#[inline]
fn to_string_non_raw(&self) -> String {
let ident_string = self.to_string();
ident_string.trim_start_matches("r#").into()
}

#[inline]
fn to_uppercase(&self) -> Self {
// This should be valid because keywords are lowercase.
format_ident!("{}", self.to_string_non_raw().to_uppercase())
}

#[inline]
fn with_suffix(&self, suffix: &str) -> Ident {
format_ident!("{}_{}", self.to_uppercase(), suffix)
}
}

#[inline]
pub fn into_stream(e: &Error) -> TokenStream {
e.to_compile_error().into()
}
Expand Down Expand Up @@ -131,7 +126,6 @@ impl<T: Parse> Parse for Parenthesised<T> {
pub struct AsOption<T>(pub Option<T>);

impl<T> AsOption<T> {
#[inline]
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> AsOption<U> {
AsOption(self.0.map(f))
}
Expand All @@ -147,7 +141,6 @@ impl<T: ToTokens> ToTokens for AsOption<T> {
}

impl<T> Default for AsOption<T> {
#[inline]
fn default() -> Self {
AsOption(None)
}
Expand All @@ -174,7 +167,6 @@ impl ToTokens for Argument {
}
}

#[inline]
pub fn generate_type_validation(have: &Type, expect: &Type) -> syn::Stmt {
parse_quote! {
serenity::static_assertions::assert_type_eq_all!(#have, #expect);
Expand Down Expand Up @@ -247,13 +239,11 @@ pub fn create_declaration_validations(fun: &mut CommandFun, dec_for: DeclarFor)
Ok(())
}

#[inline]
pub fn create_return_type_validation(r#fn: &mut CommandFun, expect: &Type) {
let stmt = generate_type_validation(&r#fn.ret, expect);
r#fn.body.insert(0, stmt);
}

#[inline]
pub fn populate_fut_lifetimes_on_refs(args: &mut Vec<Argument>) {
for arg in args {
if let Type::Reference(reference) = &mut arg.kind {
Expand Down
5 changes: 0 additions & 5 deletions src/builder/create_allowed_mentions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,30 @@ impl<'a> CreateAllowedMentions<'a> {
}

/// Sets the *specific* users that will be allowed mentionable.
#[inline]
pub fn users(mut self, users: impl Into<Cow<'a, [UserId]>>) -> Self {
self.users = users.into();
self
}

/// Clear the list of mentionable users.
#[inline]
pub fn empty_users(mut self) -> Self {
self.users = Cow::default();
self
}

/// Sets the *specific* roles that will be allowed mentionable.
#[inline]
pub fn roles(mut self, roles: impl Into<Cow<'a, [RoleId]>>) -> Self {
self.roles = roles.into();
self
}

/// Clear the list of mentionable roles.
#[inline]
pub fn empty_roles(mut self) -> Self {
self.roles = Cow::default();
self
}

/// Makes the reply mention/ping the user.
#[inline]
pub fn replied_user(mut self, mention_user: bool) -> Self {
self.replied_user = Some(mention_user);
self
Expand Down
10 changes: 0 additions & 10 deletions src/builder/create_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,11 @@ impl<'a> CreateEmbed<'a> {
/// Set the colour of the left-hand side of the embed.
///
/// This is an alias of [`Self::colour`].
#[inline]
pub fn color<C: Into<Colour>>(self, colour: C) -> Self {
self.colour(colour)
}

/// Set the colour of the left-hand side of the embed.
#[inline]
pub fn colour<C: Into<Colour>>(mut self, colour: C) -> Self {
self.colour = Some(colour.into());
self
Expand All @@ -86,7 +84,6 @@ impl<'a> CreateEmbed<'a> {
/// Set the description of the embed.
///
/// **Note**: This can't be longer than 4096 characters.
#[inline]
pub fn description(mut self, description: impl Into<Cow<'a, str>>) -> Self {
self.description = Some(description.into());
self
Expand All @@ -96,7 +93,6 @@ impl<'a> CreateEmbed<'a> {
///
/// **Note**: Maximum amount of characters you can put is 256 in a field name and 1024 in a
/// field value.
#[inline]
pub fn field(
mut self,
name: impl Into<Cow<'a, str>>,
Expand Down Expand Up @@ -138,7 +134,6 @@ impl<'a> CreateEmbed<'a> {
}

/// Set the image associated with the embed. This only supports HTTP(S).
#[inline]
pub fn image(mut self, url: impl Into<Cow<'a, str>>) -> Self {
self.image = Some(CreateEmbedImage {
url: url.into(),
Expand All @@ -147,7 +142,6 @@ impl<'a> CreateEmbed<'a> {
}

/// Set the thumbnail of the embed. This only supports HTTP(S).
#[inline]
pub fn thumbnail(mut self, url: impl Into<Cow<'a, str>>) -> Self {
self.thumbnail = Some(CreateEmbedImage {
url: url.into(),
Expand All @@ -169,21 +163,18 @@ impl<'a> CreateEmbed<'a> {
/// let timestamp: Timestamp = "2004-06-08T16:04:23Z".parse().expect("Invalid timestamp!");
/// let embed = CreateEmbed::new().title("hello").timestamp(timestamp);
/// ```
#[inline]
pub fn timestamp<T: Into<Timestamp>>(mut self, timestamp: T) -> Self {
self.timestamp = Some(timestamp.into());
self
}

/// Set the title of the embed.
#[inline]
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
self.title = Some(title.into());
self
}

/// Set the URL to direct to when clicking on the title.
#[inline]
pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self {
self.url = Some(url.into());
self
Expand All @@ -195,7 +186,6 @@ impl<'a> CreateEmbed<'a> {
/// with the provided filename. Or else this won't work.
///
/// [`ChannelId::send_files`]: crate::model::id::ChannelId::send_files
#[inline]
pub fn attachment(self, filename: impl Into<String>) -> Self {
let mut filename = filename.into();
filename.insert_str(0, "attachment://");
Expand Down
1 change: 0 additions & 1 deletion src/builder/create_interaction_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl<'a> CreateInteractionResponseMessage<'a> {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
#[inline]
pub fn content(mut self, content: impl Into<Cow<'a, str>>) -> Self {
self.content = Some(content.into());
self
Expand Down
1 change: 0 additions & 1 deletion src/builder/create_interaction_response_followup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl<'a> CreateInteractionResponseFollowup<'a> {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
#[inline]
pub fn content(mut self, content: impl Into<Cow<'a, str>>) -> Self {
self.content = Some(content.into());
self
Expand Down
2 changes: 0 additions & 2 deletions src/builder/create_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl<'a> CreateMessage<'a> {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
#[inline]
pub fn content(mut self, content: impl Into<Cow<'a, str>>) -> Self {
self.content = Some(content.into());
self
Expand Down Expand Up @@ -140,7 +139,6 @@ impl<'a> CreateMessage<'a> {
}

/// Adds a list of reactions to create after the message's sent.
#[inline]
pub fn reactions(mut self, reactions: impl Into<Cow<'a, [ReactionType]>>) -> Self {
self.reactions = reactions.into();
self
Expand Down
1 change: 0 additions & 1 deletion src/builder/edit_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ impl<'a> EditChannel<'a> {
///
/// [text]: ChannelType::Text
/// [voice]: ChannelType::Voice
#[inline]
pub fn category(mut self, category: Option<ChannelId>) -> Self {
self.parent_id = Some(category);
self
Expand Down
3 changes: 0 additions & 3 deletions src/builder/edit_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ impl<'a> EditGuild<'a> {

/// Set the "AFK voice channel" that users are to move to if they have been AFK for an amount
/// of time, configurable by [`Self::afk_timeout`]. Pass [`None`] to unset the current value.
#[inline]
pub fn afk_channel(mut self, channel: Option<ChannelId>) -> Self {
self.afk_channel_id = Some(channel);
self
Expand Down Expand Up @@ -146,7 +145,6 @@ impl<'a> EditGuild<'a> {
/// Transfers the ownership of the guild to another user by Id.
///
/// **Note**: The current user must be the owner of the guild.
#[inline]
pub fn owner(mut self, user_id: impl Into<UserId>) -> Self {
self.owner_id = Some(user_id.into());
self
Expand Down Expand Up @@ -266,7 +264,6 @@ impl<'a> EditGuild<'a> {
/// # Ok(())
/// # }
/// ```
#[inline]
pub fn verification_level(mut self, verification_level: impl Into<VerificationLevel>) -> Self {
self.verification_level = Some(verification_level.into());
self
Expand Down
1 change: 0 additions & 1 deletion src/builder/edit_interaction_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl<'a> EditInteractionResponse<'a> {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
#[inline]
pub fn content(self, content: impl Into<Cow<'a, str>>) -> Self {
Self(self.0.content(content))
}
Expand Down
1 change: 0 additions & 1 deletion src/builder/edit_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ impl<'a> EditMember<'a> {
/// **Note**: Requires the [Move Members] permission.
///
/// [Move Members]: Permissions::MOVE_MEMBERS
#[inline]
pub fn voice_channel(mut self, channel_id: impl Into<ChannelId>) -> Self {
self.channel_id = Some(Some(channel_id.into()));
self
Expand Down
1 change: 0 additions & 1 deletion src/builder/edit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl<'a> EditMessage<'a> {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
#[inline]
pub fn content(mut self, content: impl Into<Cow<'a, str>>) -> Self {
self.content = Some(content.into());
self
Expand Down
2 changes: 0 additions & 2 deletions src/builder/edit_scheduled_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl<'a> EditScheduledEvent<'a> {
}

/// Sets the start time of the scheduled event.
#[inline]
pub fn start_time(mut self, timestamp: impl Into<Timestamp>) -> Self {
self.scheduled_start_time = Some(timestamp.into());
self
Expand All @@ -86,7 +85,6 @@ impl<'a> EditScheduledEvent<'a> {
///
/// [`kind`]: EditScheduledEvent::kind
/// [`External`]: ScheduledEventType::External
#[inline]
pub fn end_time(mut self, timestamp: impl Into<Timestamp>) -> Self {
self.scheduled_end_time = Some(timestamp.into());
self
Expand Down
Loading

0 comments on commit 820a91a

Please sign in to comment.