diff options
| author | bors <bors@rust-lang.org> | 2015-04-19 19:32:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-04-19 19:32:45 +0000 |
| commit | da355efc1c8bde662da6f0289b492ce694bb398c (patch) | |
| tree | 0168f4afe1981d4c4d3185493193d8770fd630f9 /src/libcollections | |
| parent | c6b8d96abd116090af13f1c2c5fe8d5b7fc494d2 (diff) | |
| parent | f055054eab2a510ad3252599a015f660eef6aedd (diff) | |
| download | rust-da355efc1c8bde662da6f0289b492ce694bb398c.tar.gz rust-da355efc1c8bde662da6f0289b492ce694bb398c.zip | |
Auto merge of #24517 - erickt:str, r=alexcrichton
This implementation is currently about 3-4 times faster than using the `.to_string()` based approach. I would also suggest we deprecate `String::from_str` since it's redundant with the stable `String::from` method, but I'll leave that for a future PR.
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/string.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 74af5783fa8..81710286fde 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1013,9 +1013,20 @@ impl AsRef<str> for String { #[stable(feature = "rust1", since = "1.0.0")] impl<'a> From<&'a str> for String { + #[cfg(not(test))] #[inline] fn from(s: &'a str) -> String { - s.to_string() + String { vec: <[_]>::to_vec(s.as_bytes()) } + } + + // HACK(japaric): with cfg(test) the inherent `[T]::to_vec` method, which is + // required for this method definition, is not available. Since we don't + // require this method for testing purposes, I'll just stub it + // NB see the slice::hack module in slice.rs for more information + #[inline] + #[cfg(test)] + fn from(_: &str) -> String { + panic!("not available with cfg(test)"); } } |
