Skip to content

Commit 827fdf8

Browse files
committed
use into_boxed_str to shrink before we leek
1 parent 26bfc7d commit 827fdf8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/cargo/core/interning.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use std::collections::HashSet;
44
use std::slice;
55
use std::str;
66
use std::mem;
7+
use std::cmp::Ordering;
78

89
pub fn leek(s: String) -> &'static str {
9-
let ptr = s.as_ptr();
10-
let len = s.len();
11-
mem::forget(s);
10+
let boxed = s.into_boxed_str();
11+
let ptr = boxed.as_ptr();
12+
let len = boxed.len();
13+
mem::forget(boxed);
1214
unsafe {
1315
let slice = slice::from_raw_parts(ptr, len);
1416
str::from_utf8_unchecked(slice)
@@ -49,3 +51,18 @@ impl fmt::Debug for InternedString {
4951
write!(f, "InternedString {{ {} }}", self.to_inner())
5052
}
5153
}
54+
55+
impl Ord for InternedString {
56+
fn cmp(&self, other: &InternedString) -> Ordering {
57+
self.to_inner().cmp(&other.to_inner())
58+
}
59+
}
60+
61+
impl PartialOrd for InternedString {
62+
fn partial_cmp(&self, other: &InternedString) -> Option<Ordering> {
63+
Some(self.cmp(other))
64+
}
65+
}
66+
67+
unsafe impl Send for InternedString {}
68+
unsafe impl Sync for InternedString {}

0 commit comments

Comments
 (0)