Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6fff089

Browse files
committedFeb 24, 2025··
feat: inline always hint for some method
Signed-off-by: Woshiluo Luo <woshiluo.luo@outlook.com>
1 parent 32f3a1e commit 6fff089

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
 

‎src/ser/patch.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Patch<'se> {
99
}
1010

1111
impl<'se> Patch<'se> {
12+
#[inline(always)]
1213
pub fn new(name: &'se str, data: &'se dyn erased_serde::Serialize) -> Patch<'se> {
1314
Patch {
1415
name,
@@ -18,15 +19,18 @@ impl<'se> Patch<'se> {
1819
}
1920
}
2021

22+
#[inline(always)]
2123
pub fn init(&self) {
2224
self.matched_depth.set(0);
2325
self.parsed.set(false);
2426
}
2527

28+
#[inline(always)]
2629
pub fn get_depth(&self) -> usize {
2730
self.name.split('/').count() - 1
2831
}
2932

33+
#[inline(always)]
3034
pub fn get_depth_path(&self, x: usize) -> &'se str {
3135
if x == 0 {
3236
return "";
@@ -36,6 +40,7 @@ impl<'se> Patch<'se> {
3640

3741
// I hope to impl serde::ser::Serializer, but erase_serialize's return value is different from
3842
// normal serialize, so we do this.
43+
#[inline(always)]
3944
pub fn serialize(&self, serializer: &mut Serializer<'se>) {
4045
self.parsed.set(true);
4146
self.data
@@ -49,10 +54,12 @@ pub struct PatchList<'se> {
4954
}
5055

5156
impl<'se> PatchList<'se> {
57+
#[inline(always)]
5258
pub fn new(list: &'se [Patch<'se>]) -> PatchList<'se> {
5359
PatchList { list }
5460
}
5561

62+
#[inline(always)]
5663
pub fn step_forward(&self, name: &'se str, depth: usize) -> Option<&'se Patch<'se>> {
5764
let mut matched_patch = None;
5865
self.list.iter().for_each(|patch| {
@@ -69,6 +76,7 @@ impl<'se> PatchList<'se> {
6976
matched_patch
7077
}
7178

79+
#[inline(always)]
7280
pub fn step_back(&self, depth: usize) {
7381
self.list.iter().for_each(|patch| {
7482
if patch.matched_depth.get() == depth {
@@ -77,6 +85,7 @@ impl<'se> PatchList<'se> {
7785
});
7886
}
7987

88+
#[inline(always)]
8089
pub fn add_list(&self, depth: usize) -> impl Iterator<Item = &'se Patch<'se>> + use<'se> {
8190
self.list.iter().filter(move |x| {
8291
x.matched_depth.get() == depth && x.get_depth() == depth + 1 && !x.parsed.get()

‎src/ser/serializer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct Serializer<'se> {
2020
}
2121

2222
impl<'se> Serializer<'se> {
23+
#[inline(always)]
2324
pub fn new(
2425
dst: &'se mut Pointer<'se>,
2526
cache: &'se mut StringBlock<'se>,

‎src/ser/string_block.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ pub struct StringBlock<'se> {
44
}
55

66
impl<'se> StringBlock<'se> {
7+
#[inline(always)]
78
pub fn new(dst: &'se mut [u8], end: &'se mut usize) -> StringBlock<'se> {
89
StringBlock { data: dst, end }
910
}
1011

1112
/// Will panic when len > end
1213
/// TODO: show as error
1314
/// Return (Result String, End Offset)
15+
#[inline(always)]
1416
pub fn get_str_by_offset(&self, offset: usize) -> (&str, usize) {
1517
if offset > *self.end {
1618
panic!("invalid read");
@@ -25,11 +27,14 @@ impl<'se> StringBlock<'se> {
2527
(result, pos + offset + 1)
2628
}
2729

30+
#[inline(always)]
2831
fn insert_u8(&mut self, data: u8) {
2932
self.data[*self.end] = data;
3033
*self.end += 1;
3134
}
35+
3236
/// Return the start offset of inserted string.
37+
#[inline(always)]
3338
pub fn insert_str(&mut self, name: &str) -> usize {
3439
let result = *self.end;
3540
name.bytes().for_each(|x| {
@@ -39,6 +44,7 @@ impl<'se> StringBlock<'se> {
3944
result
4045
}
4146

47+
#[inline(always)]
4248
pub fn find_or_insert(&mut self, name: &str) -> usize {
4349
let mut current_pos = 0;
4450
while current_pos < *self.end {

0 commit comments

Comments
 (0)
Please sign in to comment.