Skip to content

Commit

Permalink
Add inline annotations to wrapping function calls in ufmt
Browse files Browse the repository at this point in the history
This should make the compiler inline the function calls to increase performance.
  • Loading branch information
lmbollen committed Feb 28, 2024
1 parent cf989c3 commit fd446d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `ufmt-impl` is now `ufmt`
- `cas` is removed, atomic polyfilling is now opt-in via the `portable-atomic` feature.
- `Vec::as_mut_slice` is now a public method.
- `ufmt` functions are annotated with `inline(always)`.

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions src/ufmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{string::String, vec::Vec};
use ufmt_write::uWrite;

impl<const SIZE: usize> uDisplay for String<SIZE> {
#[inline(always)]
fn fmt<W>(&self, f: &mut ufmt::Formatter<'_, W>) -> Result<(), W::Error>
where
W: uWrite + ?Sized,
Expand All @@ -12,13 +13,15 @@ impl<const SIZE: usize> uDisplay for String<SIZE> {

impl<const N: usize> uWrite for String<N> {
type Error = ();
#[inline(always)]
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
self.push_str(s)
}
}

impl<const N: usize> uWrite for Vec<u8, N> {
type Error = ();
#[inline(always)]
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
self.extend_from_slice(s.as_bytes())
}
Expand Down

0 comments on commit fd446d8

Please sign in to comment.