Auto merge of #5121 - Eh2406:string_interning, r=alexcrichton
authorbors <bors@rust-lang.org>
Wed, 7 Mar 2018 22:54:54 +0000 (22:54 +0000)
committerbors <bors@rust-lang.org>
Wed, 7 Mar 2018 22:54:54 +0000 (22:54 +0000)
String interning

This builds on the work from #5118. This interns the strings in the part of resolver that gets cloned a lot.

In a test on https://github.com/rust-lang/cargo/issues/4810#issuecomment-357553286
Before we got to 1700000 ticks in ~(63 to 67) sec from #5118
After we got to 1700000 ticks in ~(42 to 45) sec

The interning code itself would be much better with a `leak` function that converts a `String` to a `&'static str`. Something like:
```rust
pub fn leek(s: String) -> &'static str {
    let ptr = s.as_ptr();
    let len = s.len();
    mem::forget(s);
    unsafe {
        let slice = slice::from_raw_parts(ptr, len);
        str::from_utf8(slice).unwrap()
    }
}
```
but "there is no unsafe in Cargo", and I am not the best at unsafe. So I just `to_string` and lived with the extra copy. Is there a better way to hand out references?

I assumed that `InternedString::new` world start appearing in profile result, and that we would want `PackageId`, and `Summary`, Et Al. to store the `InternedString`. That is why I put the interner in a shared folder. So far it is just used in the resolver. It may make sense for a lot more of the Strings to be interned, but with the extra copy... I have not explored it yet.

1  2 
src/cargo/core/resolver/mod.rs

Simple merge