Skip to content

Commit bcc2f05

Browse files
committed
[new_zonefile/simple] Return origin names by reference
1 parent 925cd28 commit bcc2f05

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/new_zonefile/simple.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ impl<R: io::BufRead> ZonefileScanner<R> {
166166
}
167167

168168
/// Scan a directive.
169-
fn scan_directive(
169+
fn scan_directive<'a>(
170170
entry: &[u8],
171171
origin: &mut Option<RevNameBuf>,
172172
last_ttl: &mut Option<TTL>,
173-
alloc: &bumpalo::Bump,
173+
alloc: &'a bumpalo::Bump,
174174
buffer: &mut Vec<u8>,
175-
) -> Result<Option<Entry<'static>>, DirectiveError> {
175+
) -> Result<Option<Entry<'a>>, DirectiveError> {
176176
// Extract the directive.
177177
let pos = entry
178178
.iter()
@@ -200,12 +200,12 @@ impl<R: io::BufRead> ZonefileScanner<R> {
200200
}
201201

202202
/// Scan an include directive.
203-
fn scan_include_directive(
203+
fn scan_include_directive<'a>(
204204
mut scanner: Scanner<'_>,
205205
origin: &Option<RevNameBuf>,
206-
alloc: &bumpalo::Bump,
206+
alloc: &'a bumpalo::Bump,
207207
buffer: &mut Vec<u8>,
208-
) -> Result<Entry<'static>, DirectiveError> {
208+
) -> Result<Entry<'a>, DirectiveError> {
209209
let file_name: PathBuf = scanner
210210
.scan_token(buffer)
211211
.transpose()
@@ -222,6 +222,11 @@ impl<R: io::BufRead> ZonefileScanner<R> {
222222
.map_err(|_| DirectiveError::InvalidOrigin)?,
223223
);
224224
}
225+
let origin = origin.map(|origin| {
226+
let bytes = alloc.alloc_slice_copy(origin.as_bytes());
227+
// SAFETY: 'RevName::as_bytes()' is always valid.
228+
unsafe { RevName::from_bytes_unchecked(bytes) }
229+
});
225230

226231
Ok(Entry::Include { file_name, origin })
227232
}
@@ -389,7 +394,7 @@ pub enum Entry<'a> {
389394
file_name: PathBuf,
390395

391396
/// The origin domain name to use.
392-
origin: Option<RevNameBuf>,
397+
origin: Option<&'a RevName>,
393398
},
394399
}
395400

@@ -665,7 +670,7 @@ $INCLUDE <SUBSYS>ISI-MAILBOXES.TXT
665670
})
666671
.chain([Entry::Include {
667672
file_name: PathBuf::from("<SUBSYS>ISI-MAILBOXES.TXT"),
668-
origin: Some(origin.clone()),
673+
origin: Some(&origin),
669674
}]);
670675

671676
let mut scanner = ZonefileScanner::new(source, Some(&origin));

0 commit comments

Comments
 (0)