diff options
| author | bors <bors@rust-lang.org> | 2015-05-02 04:35:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-05-02 04:35:33 +0000 |
| commit | 700b4c160bebb812951387074331a71d54805db0 (patch) | |
| tree | a94c8d8b02890683167d9f4f7224292a19fedc8d /src/libsyntax | |
| parent | b858b7f4ced2acaabcf1d0f59abd4a0c4a62ded3 (diff) | |
| parent | da03c9df33177d77029c52f8a68a5d214a6e83c7 (diff) | |
| download | rust-700b4c160bebb812951387074331a71d54805db0.tar.gz rust-700b4c160bebb812951387074331a71d54805db0.zip | |
Auto merge of #25028 - bluss:drain-string, r=alexcrichton
collections: Implement String::drain(range) according to RFC 574 `.drain(range)` is unstable and under feature(collections_drain). This adds a safe way to remove any range of a String as efficiently as possible. As noted in the code, this drain iterator has none of the memory safety issues of the vector version. RFC tracking issue is #23055
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 1 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 5e0cb647c8b..decc6f01eef 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -543,7 +543,7 @@ impl CodeMap { } } - pub fn new_filemap(&self, filename: FileName, src: String) -> Rc<FileMap> { + pub fn new_filemap(&self, filename: FileName, mut src: String) -> Rc<FileMap> { let mut files = self.files.borrow_mut(); let start_pos = match files.last() { None => 0, @@ -551,13 +551,9 @@ impl CodeMap { }; // Remove utf-8 BOM if any. - // FIXME #12884: no efficient/safe way to remove from the start of a string - // and reuse the allocation. - let mut src = if src.starts_with("\u{feff}") { - String::from(&src[3..]) - } else { - String::from(&src[..]) - }; + if src.starts_with("\u{feff}") { + src.drain(..3); + } // Append '\n' in case it's not already there. // This is a workaround to prevent CodeMap.lookup_filemap_idx from diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 275400009f5..330fe86deeb 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -27,6 +27,7 @@ #![feature(associated_consts)] #![feature(collections)] +#![feature(collections_drain)] #![feature(core)] #![feature(libc)] #![feature(rustc_private)] |
