Skip to content

Commit d1e2048

Browse files
committed
Parameterize contains_nul for BytesContainer.
1 parent 65abf96 commit d1e2048

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/libstd/path/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
158158
/// See individual Path impls for additional restrictions.
159159
#[inline]
160160
fn new<T: BytesContainer>(path: T) -> Self {
161-
assert!(!contains_nul(path.container_as_bytes()));
161+
assert!(!contains_nul(&path));
162162
unsafe { GenericPathUnsafe::new_unchecked(path) }
163163
}
164164

165165
/// Creates a new Path from a byte vector or string, if possible.
166166
/// The resulting Path will always be normalized.
167167
#[inline]
168168
fn new_opt<T: BytesContainer>(path: T) -> Option<Self> {
169-
if contains_nul(path.container_as_bytes()) {
169+
if contains_nul(&path) {
170170
None
171171
} else {
172172
Some(unsafe { GenericPathUnsafe::new_unchecked(path) })
@@ -274,7 +274,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
274274
/// Fails the task if the filename contains a NUL.
275275
#[inline]
276276
fn set_filename<T: BytesContainer>(&mut self, filename: T) {
277-
assert!(!contains_nul(filename.container_as_bytes()));
277+
assert!(!contains_nul(&filename));
278278
unsafe { self.set_filename_unchecked(filename) }
279279
}
280280
/// Replaces the extension with the given byte vector or string.
@@ -286,7 +286,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
286286
///
287287
/// Fails the task if the extension contains a NUL.
288288
fn set_extension<T: BytesContainer>(&mut self, extension: T) {
289-
assert!(!contains_nul(extension.container_as_bytes()));
289+
assert!(!contains_nul(&extension));
290290
// borrowck causes problems here too
291291
let val = {
292292
match self.filename() {
@@ -376,7 +376,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
376376
/// Fails the task if the path contains a NUL.
377377
#[inline]
378378
fn push<T: BytesContainer>(&mut self, path: T) {
379-
assert!(!contains_nul(path.container_as_bytes()));
379+
assert!(!contains_nul(&path));
380380
unsafe { self.push_unchecked(path) }
381381
}
382382
/// Pushes multiple paths (as byte vectors or strings) onto `self`.
@@ -589,8 +589,8 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
589589
}
590590

591591
#[inline(always)]
592-
fn contains_nul(v: &[u8]) -> bool {
593-
v.iter().any(|&x| x == 0)
592+
fn contains_nul<T: BytesContainer>(v: &T) -> bool {
593+
v.container_as_bytes().iter().any(|&x| x == 0)
594594
}
595595

596596
#[cfg(test)]

src/libstd/path/windows.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,13 @@ impl GenericPathUnsafe for Path {
306306
impl GenericPath for Path {
307307
#[inline]
308308
fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
309-
let s = path.container_as_str();
310-
match s {
309+
match path.container_as_str() {
311310
None => None,
312-
Some(s) => {
313-
if contains_nul(s.as_bytes()) {
311+
Some(ref s) => {
312+
if contains_nul(s) {
314313
None
315314
} else {
316-
Some(unsafe { GenericPathUnsafe::new_unchecked(s) })
315+
Some(unsafe { GenericPathUnsafe::new_unchecked(*s) })
317316
}
318317
}
319318
}

0 commit comments

Comments
 (0)