Skip to content

Commit c5fee82

Browse files
committed
fix!: use dyn trait where possible.
This reduces compile time due to avoiding duplication.
1 parent 083184c commit c5fee82

26 files changed

+175
-172
lines changed

gix-config/src/file/access/comfort.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl<'event> File<'event> {
3131
key: impl AsRef<str>,
3232
filter: &mut MetadataFilter,
3333
) -> Option<Cow<'_, BStr>> {
34-
self.raw_value_filter(section_name, subsection_name, key, filter).ok()
34+
self.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter)
35+
.ok()
3536
}
3637

3738
/// Like [`string_filter()`][File::string_filter()], but suitable for statically known `key`s like `remote.origin.url`.
@@ -40,7 +41,7 @@ impl<'event> File<'event> {
4041
key: impl Into<&'a BStr>,
4142
filter: &mut MetadataFilter,
4243
) -> Option<Cow<'_, BStr>> {
43-
let key = crate::parse::key(key)?;
44+
let key = crate::parse::key(key.into())?;
4445
self.raw_value_filter(key.section_name, key.subsection_name, key.value_name, filter)
4546
.ok()
4647
}
@@ -78,7 +79,7 @@ impl<'event> File<'event> {
7879
key: impl AsRef<str>,
7980
filter: &mut MetadataFilter,
8081
) -> Option<crate::Path<'_>> {
81-
self.raw_value_filter(section_name, subsection_name, key, filter)
82+
self.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter)
8283
.ok()
8384
.map(crate::Path::from)
8485
}
@@ -89,7 +90,7 @@ impl<'event> File<'event> {
8990
key: impl Into<&'a BStr>,
9091
filter: &mut MetadataFilter,
9192
) -> Option<crate::Path<'_>> {
92-
let key = crate::parse::key(key)?;
93+
let key = crate::parse::key(key.into())?;
9394
self.path_filter(key.section_name, key.subsection_name, key.value_name, filter)
9495
}
9596

@@ -141,7 +142,7 @@ impl<'event> File<'event> {
141142
key: impl Into<&'a BStr>,
142143
filter: &mut MetadataFilter,
143144
) -> Option<Result<bool, value::Error>> {
144-
let key = crate::parse::key(key)?;
145+
let key = crate::parse::key(key.into())?;
145146
self.boolean_filter(key.section_name, key.subsection_name, key.value_name, filter)
146147
}
147148

@@ -168,7 +169,9 @@ impl<'event> File<'event> {
168169
key: impl AsRef<str>,
169170
filter: &mut MetadataFilter,
170171
) -> Option<Result<i64, value::Error>> {
171-
let int = self.raw_value_filter(section_name, subsection_name, key, filter).ok()?;
172+
let int = self
173+
.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter)
174+
.ok()?;
172175
Some(crate::Integer::try_from(int.as_ref()).and_then(|b| {
173176
b.to_decimal()
174177
.ok_or_else(|| value::Error::new("Integer overflow", int.into_owned()))
@@ -181,7 +184,7 @@ impl<'event> File<'event> {
181184
key: impl Into<&'a BStr>,
182185
filter: &mut MetadataFilter,
183186
) -> Option<Result<i64, value::Error>> {
184-
let key = crate::parse::key(key)?;
187+
let key = crate::parse::key(key.into())?;
185188
self.integer_filter(key.section_name, key.subsection_name, key.value_name, filter)
186189
}
187190

@@ -192,12 +195,13 @@ impl<'event> File<'event> {
192195
subsection_name: Option<&BStr>,
193196
key: impl AsRef<str>,
194197
) -> Option<Vec<Cow<'_, BStr>>> {
195-
self.raw_values(section_name, subsection_name, key).ok()
198+
self.raw_values(section_name.as_ref(), subsection_name, key.as_ref())
199+
.ok()
196200
}
197201

198202
/// Like [`strings()`][File::strings()], but suitable for statically known `key`s like `remote.origin.url`.
199203
pub fn strings_by_key<'a>(&self, key: impl Into<&'a BStr>) -> Option<Vec<Cow<'_, BStr>>> {
200-
let key = crate::parse::key(key)?;
204+
let key = crate::parse::key(key.into())?;
201205
self.strings(key.section_name, key.subsection_name, key.value_name)
202206
}
203207

@@ -209,7 +213,8 @@ impl<'event> File<'event> {
209213
key: impl AsRef<str>,
210214
filter: &mut MetadataFilter,
211215
) -> Option<Vec<Cow<'_, BStr>>> {
212-
self.raw_values_filter(section_name, subsection_name, key, filter).ok()
216+
self.raw_values_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter)
217+
.ok()
213218
}
214219

215220
/// Like [`strings_filter()`][File::strings_filter()], but suitable for statically known `key`s like `remote.origin.url`.
@@ -218,7 +223,7 @@ impl<'event> File<'event> {
218223
key: impl Into<&'a BStr>,
219224
filter: &mut MetadataFilter,
220225
) -> Option<Vec<Cow<'_, BStr>>> {
221-
let key = crate::parse::key(key)?;
226+
let key = crate::parse::key(key.into())?;
222227
self.strings_filter(key.section_name, key.subsection_name, key.value_name, filter)
223228
}
224229

@@ -247,7 +252,7 @@ impl<'event> File<'event> {
247252
key: impl AsRef<str>,
248253
filter: &mut MetadataFilter,
249254
) -> Option<Result<Vec<i64>, value::Error>> {
250-
self.raw_values_filter(section_name, subsection_name, key, filter)
255+
self.raw_values_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter)
251256
.ok()
252257
.map(|values| {
253258
values
@@ -268,7 +273,7 @@ impl<'event> File<'event> {
268273
key: impl Into<&'a BStr>,
269274
filter: &mut MetadataFilter,
270275
) -> Option<Result<Vec<i64>, value::Error>> {
271-
let key = crate::parse::key(key)?;
276+
let key = crate::parse::key(key.into())?;
272277
self.integers_filter(key.section_name, key.subsection_name, key.value_name, filter)
273278
}
274279
}

gix-config/src/file/access/mutate.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<'event> File<'event> {
1515
/// Returns the last mutable section with a given `name` and optional `subsection_name`, _if it exists_.
1616
pub fn section_mut<'a>(
1717
&'a mut self,
18-
name: impl AsRef<str>,
18+
name: &str,
1919
subsection_name: Option<&BStr>,
2020
) -> Result<SectionMut<'a, 'event>, lookup::existing::Error> {
2121
let id = self
@@ -31,10 +31,7 @@ impl<'event> File<'event> {
3131
}
3232

3333
/// Returns the last found mutable section with a given `key`, identifying the name and subsection name like `core` or `remote.origin`.
34-
pub fn section_mut_by_key<'a, 'b>(
35-
&'a mut self,
36-
key: impl Into<&'b BStr>,
37-
) -> Result<SectionMut<'a, 'event>, lookup::existing::Error> {
34+
pub fn section_mut_by_key<'a>(&'a mut self, key: &BStr) -> Result<SectionMut<'a, 'event>, lookup::existing::Error> {
3835
let key = section::unvalidated::Key::parse(key).ok_or(lookup::existing::Error::KeyMissing)?;
3936
self.section_mut(key.section_name, key.subsection_name)
4037
}
@@ -50,7 +47,7 @@ impl<'event> File<'event> {
5047
/// Returns the last mutable section with a given `name` and optional `subsection_name`, _if it exists_, or create a new section.
5148
pub fn section_mut_or_create_new<'a>(
5249
&'a mut self,
53-
name: impl AsRef<str>,
50+
name: &str,
5451
subsection_name: Option<&BStr>,
5552
) -> Result<SectionMut<'a, 'event>, section::header::Error> {
5653
self.section_mut_or_create_new_filter(name, subsection_name, &mut |_| true)
@@ -60,11 +57,10 @@ impl<'event> File<'event> {
6057
/// a new section.
6158
pub fn section_mut_or_create_new_filter<'a>(
6259
&'a mut self,
63-
name: impl AsRef<str>,
60+
name: &str,
6461
subsection_name: Option<&BStr>,
6562
filter: &mut MetadataFilter,
6663
) -> Result<SectionMut<'a, 'event>, section::header::Error> {
67-
let name = name.as_ref();
6864
match self
6965
.section_ids_by_name_and_subname(name.as_ref(), subsection_name)
7066
.ok()
@@ -82,7 +78,10 @@ impl<'event> File<'event> {
8278
.expect("BUG: Section did not have id from lookup")
8379
.to_mut(nl))
8480
}
85-
None => self.new_section(name.to_owned(), subsection_name.map(|n| Cow::Owned(n.to_owned()))),
81+
None => self.new_section(
82+
name.to_owned().into(),
83+
subsection_name.map(|n| Cow::Owned(n.to_owned())),
84+
),
8685
}
8786
}
8887

@@ -92,7 +91,7 @@ impl<'event> File<'event> {
9291
/// is returned.
9392
pub fn section_mut_filter<'a>(
9493
&'a mut self,
95-
name: impl AsRef<str>,
94+
name: &str,
9695
subsection_name: Option<&BStr>,
9796
filter: &mut MetadataFilter,
9897
) -> Result<Option<file::SectionMut<'a, 'event>>, lookup::existing::Error> {
@@ -109,9 +108,9 @@ impl<'event> File<'event> {
109108

110109
/// Like [`section_mut_filter()`][File::section_mut_filter()], but identifies the with a given `key`,
111110
/// like `core` or `remote.origin`.
112-
pub fn section_mut_filter_by_key<'a, 'b>(
111+
pub fn section_mut_filter_by_key<'a>(
113112
&'a mut self,
114-
key: impl Into<&'b BStr>,
113+
key: &BStr,
115114
filter: &mut MetadataFilter,
116115
) -> Result<Option<file::SectionMut<'a, 'event>>, lookup::existing::Error> {
117116
let key = section::unvalidated::Key::parse(key).ok_or(lookup::existing::Error::KeyMissing)?;
@@ -131,7 +130,7 @@ impl<'event> File<'event> {
131130
/// # use gix_config::File;
132131
/// # use std::convert::TryFrom;
133132
/// let mut git_config = gix_config::File::default();
134-
/// let section = git_config.new_section("hello", Some(Cow::Borrowed("world".into())))?;
133+
/// let section = git_config.new_section("hello".into(), Some(Cow::Borrowed("world".into())))?;
135134
/// let nl = section.newline().to_owned();
136135
/// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}"));
137136
/// # Ok::<(), Box<dyn std::error::Error>>(())
@@ -146,18 +145,18 @@ impl<'event> File<'event> {
146145
/// # use bstr::ByteSlice;
147146
/// # use gix_config::parse::section;
148147
/// let mut git_config = gix_config::File::default();
149-
/// let mut section = git_config.new_section("hello", Some(Cow::Borrowed("world".into())))?;
148+
/// let mut section = git_config.new_section("hello".into(), Some(Cow::Borrowed("world".into())))?;
150149
/// section.push(section::Key::try_from("a")?, Some("b".into()));
151150
/// let nl = section.newline().to_owned();
152151
/// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}"));
153-
/// let _section = git_config.new_section("core", None);
152+
/// let _section = git_config.new_section("core".into(), None);
154153
/// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}[core]{nl}"));
155154
/// # Ok::<(), Box<dyn std::error::Error>>(())
156155
/// ```
157156
pub fn new_section(
158157
&mut self,
159-
name: impl Into<Cow<'event, str>>,
160-
subsection: impl Into<Option<Cow<'event, BStr>>>,
158+
name: Cow<'event, str>,
159+
subsection: Option<Cow<'event, BStr>>,
161160
) -> Result<SectionMut<'_, 'event>, section::header::Error> {
162161
let id = self.push_section_internal(file::Section::new(name, subsection, OwnShared::clone(&self.meta))?);
163162
let nl = self.detect_newline_style_smallvec();
@@ -203,11 +202,7 @@ impl<'event> File<'event> {
203202
/// assert_eq!(git_config.to_string(), "[hello \"world\"]\n some-value = 4\n");
204203
/// # Ok::<(), Box<dyn std::error::Error>>(())
205204
/// ```
206-
pub fn remove_section<'a>(
207-
&mut self,
208-
name: &str,
209-
subsection_name: impl Into<Option<&'a BStr>>,
210-
) -> Option<file::Section<'event>> {
205+
pub fn remove_section(&mut self, name: &str, subsection_name: Option<&BStr>) -> Option<file::Section<'event>> {
211206
let id = self
212207
.section_ids_by_name_and_subname(name, subsection_name.into())
213208
.ok()?
@@ -252,10 +247,10 @@ impl<'event> File<'event> {
252247
/// if at least one section matched the `filter`.
253248
/// If multiple sections have the same name, then the last one is returned. Note that
254249
/// later sections with the same name have precedent over earlier ones.
255-
pub fn remove_section_filter<'a>(
250+
pub fn remove_section_filter(
256251
&mut self,
257252
name: &str,
258-
subsection_name: impl Into<Option<&'a BStr>>,
253+
subsection_name: Option<&BStr>,
259254
filter: &mut MetadataFilter,
260255
) -> Option<file::Section<'event>> {
261256
let id = self
@@ -283,12 +278,12 @@ impl<'event> File<'event> {
283278

284279
/// Renames the section with `name` and `subsection_name`, modifying the last matching section
285280
/// to use `new_name` and `new_subsection_name`.
286-
pub fn rename_section<'a>(
281+
pub fn rename_section(
287282
&mut self,
288-
name: impl AsRef<str>,
289-
subsection_name: impl Into<Option<&'a BStr>>,
290-
new_name: impl Into<Cow<'event, str>>,
291-
new_subsection_name: impl Into<Option<Cow<'event, BStr>>>,
283+
name: &str,
284+
subsection_name: Option<&BStr>,
285+
new_name: Cow<'event, str>,
286+
new_subsection_name: Option<Cow<'event, BStr>>,
292287
) -> Result<(), rename_section::Error> {
293288
let id = self
294289
.section_ids_by_name_and_subname(name.as_ref(), subsection_name.into())?
@@ -304,12 +299,12 @@ impl<'event> File<'event> {
304299
///
305300
/// Note that the otherwise unused [`lookup::existing::Error::KeyMissing`] variant is used to indicate
306301
/// that the `filter` rejected all candidates, leading to no section being renamed after all.
307-
pub fn rename_section_filter<'a>(
302+
pub fn rename_section_filter(
308303
&mut self,
309-
name: impl AsRef<str>,
310-
subsection_name: impl Into<Option<&'a BStr>>,
311-
new_name: impl Into<Cow<'event, str>>,
312-
new_subsection_name: impl Into<Option<Cow<'event, BStr>>>,
304+
name: &str,
305+
subsection_name: Option<&BStr>,
306+
new_name: Cow<'event, str>,
307+
new_subsection_name: Option<Cow<'event, BStr>>,
313308
filter: &mut MetadataFilter,
314309
) -> Result<(), rename_section::Error> {
315310
let id = self

0 commit comments

Comments
 (0)