Skip to content

Commit 85476a2

Browse files
committed
optimize fuzzer allocations for slightly better performance
1 parent f9d566f commit 85476a2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

gix-config-value/fuzz/fuzz_targets/fuzz_value.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ extern crate libfuzzer_sys;
44

55
use anyhow::Result;
66
use arbitrary::Arbitrary;
7-
use bstr::{BStr, BString};
7+
use bstr::BStr;
88
use gix_config_value::{
99
color::{Attribute, Name},
1010
path::interpolate::Context,
1111
Boolean, Color, Integer, Path,
1212
};
1313
use libfuzzer_sys::fuzz_target;
14-
use std::{borrow::Cow, hint::black_box, str::FromStr};
14+
use std::{borrow::Cow, fmt::Write, hint::black_box, str::FromStr};
1515

1616
#[derive(Debug, Arbitrary)]
1717
struct Ctx<'a> {
@@ -29,16 +29,17 @@ fn fuzz(ctx: Ctx) -> Result<()> {
2929

3030
_ = black_box(Color::try_from(BStr::new(ctx.color_str)))?;
3131

32+
let mut buf = String::with_capacity(128);
3233
let a = Attribute::from_str(ctx.attribute_str)?;
33-
_ = black_box(format!("{a}"));
34+
_ = black_box(write!(&mut buf, "{a}"));
3435

3536
let name = Name::from_str(ctx.name_str)?;
36-
_ = black_box(format!("{name}"));
37+
_ = black_box(write!(&mut buf, "{name}"));
3738

3839
let i = Integer::try_from(BStr::new(ctx.integer_str))?;
3940
_ = black_box(i.to_decimal());
4041

41-
let p = Path::try_from(Cow::Owned(BString::from(ctx.path_str)))?;
42+
let p = Path::from(Cow::Borrowed(BStr::new(ctx.path_str)));
4243
_ = black_box(p.interpolate(Context::default()));
4344

4445
Ok(())

0 commit comments

Comments
 (0)