Add some more #[inline] annotations for trivial functions (#2817)

Looking at some profiles these or their related functions were all
showing up, so this commit adds `#[inline]` to allow cross-crate
inlining by default.
This commit is contained in:
Alex Crichton
2021-04-08 12:23:54 -05:00
committed by GitHub
parent 5c4c03d278
commit c77ea0c5c7
5 changed files with 23 additions and 0 deletions

View File

@@ -70,21 +70,25 @@ macro_rules! entity_impl {
// Basic traits. // Basic traits.
($entity:ident) => { ($entity:ident) => {
impl $crate::EntityRef for $entity { impl $crate::EntityRef for $entity {
#[inline]
fn new(index: usize) -> Self { fn new(index: usize) -> Self {
debug_assert!(index < ($crate::__core::u32::MAX as usize)); debug_assert!(index < ($crate::__core::u32::MAX as usize));
$entity(index as u32) $entity(index as u32)
} }
#[inline]
fn index(self) -> usize { fn index(self) -> usize {
self.0 as usize self.0 as usize
} }
} }
impl $crate::packed_option::ReservedValue for $entity { impl $crate::packed_option::ReservedValue for $entity {
#[inline]
fn reserved_value() -> $entity { fn reserved_value() -> $entity {
$entity($crate::__core::u32::MAX) $entity($crate::__core::u32::MAX)
} }
#[inline]
fn is_reserved_value(&self) -> bool { fn is_reserved_value(&self) -> bool {
self.0 == $crate::__core::u32::MAX self.0 == $crate::__core::u32::MAX
} }
@@ -93,6 +97,7 @@ macro_rules! entity_impl {
impl $entity { impl $entity {
/// Create a new instance from a `u32`. /// Create a new instance from a `u32`.
#[allow(dead_code)] #[allow(dead_code)]
#[inline]
pub fn from_u32(x: u32) -> Self { pub fn from_u32(x: u32) -> Self {
debug_assert!(x < $crate::__core::u32::MAX); debug_assert!(x < $crate::__core::u32::MAX);
$entity(x) $entity(x)
@@ -100,6 +105,7 @@ macro_rules! entity_impl {
/// Return the underlying index value as a `u32`. /// Return the underlying index value as a `u32`.
#[allow(dead_code)] #[allow(dead_code)]
#[inline]
pub fn as_u32(self) -> u32 { pub fn as_u32(self) -> u32 {
self.0 self.0
} }

View File

@@ -448,12 +448,14 @@ impl Module {
} }
/// Convert a `DefinedFuncIndex` into a `FuncIndex`. /// Convert a `DefinedFuncIndex` into a `FuncIndex`.
#[inline]
pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex { pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex {
FuncIndex::new(self.num_imported_funcs + defined_func.index()) FuncIndex::new(self.num_imported_funcs + defined_func.index())
} }
/// Convert a `FuncIndex` into a `DefinedFuncIndex`. Returns None if the /// Convert a `FuncIndex` into a `DefinedFuncIndex`. Returns None if the
/// index is an imported function. /// index is an imported function.
#[inline]
pub fn defined_func_index(&self, func: FuncIndex) -> Option<DefinedFuncIndex> { pub fn defined_func_index(&self, func: FuncIndex) -> Option<DefinedFuncIndex> {
if func.index() < self.num_imported_funcs { if func.index() < self.num_imported_funcs {
None None
@@ -465,17 +467,20 @@ impl Module {
} }
/// Test whether the given function index is for an imported function. /// Test whether the given function index is for an imported function.
#[inline]
pub fn is_imported_function(&self, index: FuncIndex) -> bool { pub fn is_imported_function(&self, index: FuncIndex) -> bool {
index.index() < self.num_imported_funcs index.index() < self.num_imported_funcs
} }
/// Convert a `DefinedTableIndex` into a `TableIndex`. /// Convert a `DefinedTableIndex` into a `TableIndex`.
#[inline]
pub fn table_index(&self, defined_table: DefinedTableIndex) -> TableIndex { pub fn table_index(&self, defined_table: DefinedTableIndex) -> TableIndex {
TableIndex::new(self.num_imported_tables + defined_table.index()) TableIndex::new(self.num_imported_tables + defined_table.index())
} }
/// Convert a `TableIndex` into a `DefinedTableIndex`. Returns None if the /// Convert a `TableIndex` into a `DefinedTableIndex`. Returns None if the
/// index is an imported table. /// index is an imported table.
#[inline]
pub fn defined_table_index(&self, table: TableIndex) -> Option<DefinedTableIndex> { pub fn defined_table_index(&self, table: TableIndex) -> Option<DefinedTableIndex> {
if table.index() < self.num_imported_tables { if table.index() < self.num_imported_tables {
None None
@@ -487,17 +492,20 @@ impl Module {
} }
/// Test whether the given table index is for an imported table. /// Test whether the given table index is for an imported table.
#[inline]
pub fn is_imported_table(&self, index: TableIndex) -> bool { pub fn is_imported_table(&self, index: TableIndex) -> bool {
index.index() < self.num_imported_tables index.index() < self.num_imported_tables
} }
/// Convert a `DefinedMemoryIndex` into a `MemoryIndex`. /// Convert a `DefinedMemoryIndex` into a `MemoryIndex`.
#[inline]
pub fn memory_index(&self, defined_memory: DefinedMemoryIndex) -> MemoryIndex { pub fn memory_index(&self, defined_memory: DefinedMemoryIndex) -> MemoryIndex {
MemoryIndex::new(self.num_imported_memories + defined_memory.index()) MemoryIndex::new(self.num_imported_memories + defined_memory.index())
} }
/// Convert a `MemoryIndex` into a `DefinedMemoryIndex`. Returns None if the /// Convert a `MemoryIndex` into a `DefinedMemoryIndex`. Returns None if the
/// index is an imported memory. /// index is an imported memory.
#[inline]
pub fn defined_memory_index(&self, memory: MemoryIndex) -> Option<DefinedMemoryIndex> { pub fn defined_memory_index(&self, memory: MemoryIndex) -> Option<DefinedMemoryIndex> {
if memory.index() < self.num_imported_memories { if memory.index() < self.num_imported_memories {
None None
@@ -509,17 +517,20 @@ impl Module {
} }
/// Test whether the given memory index is for an imported memory. /// Test whether the given memory index is for an imported memory.
#[inline]
pub fn is_imported_memory(&self, index: MemoryIndex) -> bool { pub fn is_imported_memory(&self, index: MemoryIndex) -> bool {
index.index() < self.num_imported_memories index.index() < self.num_imported_memories
} }
/// Convert a `DefinedGlobalIndex` into a `GlobalIndex`. /// Convert a `DefinedGlobalIndex` into a `GlobalIndex`.
#[inline]
pub fn global_index(&self, defined_global: DefinedGlobalIndex) -> GlobalIndex { pub fn global_index(&self, defined_global: DefinedGlobalIndex) -> GlobalIndex {
GlobalIndex::new(self.num_imported_globals + defined_global.index()) GlobalIndex::new(self.num_imported_globals + defined_global.index())
} }
/// Convert a `GlobalIndex` into a `DefinedGlobalIndex`. Returns None if the /// Convert a `GlobalIndex` into a `DefinedGlobalIndex`. Returns None if the
/// index is an imported global. /// index is an imported global.
#[inline]
pub fn defined_global_index(&self, global: GlobalIndex) -> Option<DefinedGlobalIndex> { pub fn defined_global_index(&self, global: GlobalIndex) -> Option<DefinedGlobalIndex> {
if global.index() < self.num_imported_globals { if global.index() < self.num_imported_globals {
None None
@@ -531,6 +542,7 @@ impl Module {
} }
/// Test whether the given global index is for an imported global. /// Test whether the given global index is for an imported global.
#[inline]
pub fn is_imported_global(&self, index: GlobalIndex) -> bool { pub fn is_imported_global(&self, index: GlobalIndex) -> bool {
index.index() < self.num_imported_globals index.index() < self.num_imported_globals
} }

View File

@@ -44,6 +44,7 @@ fn cast_to_u32(sz: usize) -> u32 {
} }
/// Align an offset used in this module to a specific byte-width by rounding up /// Align an offset used in this module to a specific byte-width by rounding up
#[inline]
fn align(offset: u32, width: u32) -> u32 { fn align(offset: u32, width: u32) -> u32 {
(offset + (width - 1)) / width * width (offset + (width - 1)) / width * width
} }

View File

@@ -970,6 +970,7 @@ impl InstanceHandle {
/// of the internals, there's no lifetime tracking around its validity. /// of the internals, there's no lifetime tracking around its validity.
/// You'll need to ensure that the returned handles all go out of scope at /// You'll need to ensure that the returned handles all go out of scope at
/// the same time. /// the same time.
#[inline]
pub unsafe fn clone(&self) -> InstanceHandle { pub unsafe fn clone(&self) -> InstanceHandle {
InstanceHandle { InstanceHandle {
instance: self.instance, instance: self.instance,

View File

@@ -490,17 +490,20 @@ mod test_vmshared_signature_index {
impl VMSharedSignatureIndex { impl VMSharedSignatureIndex {
/// Create a new `VMSharedSignatureIndex`. /// Create a new `VMSharedSignatureIndex`.
#[inline]
pub fn new(value: u32) -> Self { pub fn new(value: u32) -> Self {
Self(value) Self(value)
} }
/// Returns the underlying bits of the index. /// Returns the underlying bits of the index.
#[inline]
pub fn bits(&self) -> u32 { pub fn bits(&self) -> u32 {
self.0 self.0
} }
} }
impl Default for VMSharedSignatureIndex { impl Default for VMSharedSignatureIndex {
#[inline]
fn default() -> Self { fn default() -> Self {
Self::new(u32::MAX) Self::new(u32::MAX)
} }