Skip to content

Commit 8ac8ba6

Browse files
committed
Use Lrc<[u8]/str> instead of Lrc<Vec<u8>/String> in libsyntax
1 parent 5deed73 commit 8ac8ba6

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ pub enum LitKind {
12991299
/// A string literal (`"foo"`)
13001300
Str(Symbol, StrStyle),
13011301
/// A byte string (`b"foo"`)
1302-
ByteStr(Lrc<Vec<u8>>),
1302+
ByteStr(Lrc<[u8]>),
13031303
/// A byte char (`b'f'`)
13041304
Byte(u8),
13051305
/// A character literal (`'a'`)

src/libsyntax/ext/source_util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use util::small_vector::SmallVector;
2424
use std::fs::File;
2525
use std::io::prelude::*;
2626
use std::path::PathBuf;
27-
use rustc_data_structures::sync::Lrc;
2827

2928
// These macros all relate to the file system; they either return
3029
// the column/row/filename of the expression, or they include
@@ -184,7 +183,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
184183
// dependency information, but don't enter it's contents
185184
cx.codemap().new_filemap_and_lines(&file, "");
186185

187-
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes))))
186+
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::from(bytes))))
188187
}
189188
}
190189
}

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct StringReader<'a> {
6161
pub fatal_errs: Vec<DiagnosticBuilder<'a>>,
6262
// cache a direct reference to the source text, so that we don't have to
6363
// retrieve it via `self.filemap.src.as_ref().unwrap()` all the time.
64-
source_text: Lrc<String>,
64+
source_text: Lrc<str>,
6565
/// Stack of open delimiters and their spans. Used for error message.
6666
token: token::Token,
6767
span: Span,

src/libsyntax/parse/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ pub fn lit_token(lit: token::Lit, suf: Option<Symbol>, diag: Option<(Span, &Hand
428428
(true, Some(LitKind::ByteStr(byte_str_lit(&i.as_str()))))
429429
}
430430
token::ByteStrRaw(i, _) => {
431-
(true, Some(LitKind::ByteStr(Lrc::new(i.to_string().into_bytes()))))
431+
(true, Some(LitKind::ByteStr(Lrc::from(i.as_str().as_bytes()))))
432432
}
433433
}
434434
}
@@ -502,7 +502,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) {
502502
}
503503
}
504504

505-
pub fn byte_str_lit(lit: &str) -> Lrc<Vec<u8>> {
505+
pub fn byte_str_lit(lit: &str) -> Lrc<[u8]> {
506506
let mut res = Vec::with_capacity(lit.len());
507507

508508
let error = |i| format!("lexer should have rejected {} at {}", lit, i);
@@ -558,7 +558,7 @@ pub fn byte_str_lit(lit: &str) -> Lrc<Vec<u8>> {
558558
}
559559
}
560560

561-
Lrc::new(res)
561+
Lrc::from(res)
562562
}
563563

564564
pub fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>)

src/libsyntax_pos/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ pub struct FileMap {
705705
/// Indicates which crate this FileMap was imported from.
706706
pub crate_of_origin: u32,
707707
/// The complete source code
708-
pub src: Option<Lrc<String>>,
708+
pub src: Option<Lrc<str>>,
709709
/// The source code's hash
710710
pub src_hash: u128,
711711
/// The external source code (used for external crates, which will have a `None`
@@ -891,7 +891,7 @@ impl FileMap {
891891
name_was_remapped,
892892
unmapped_path: Some(unmapped_path),
893893
crate_of_origin: 0,
894-
src: Some(Lrc::new(src)),
894+
src: Some(Lrc::from(src)),
895895
src_hash,
896896
external_src: Lock::new(ExternalSource::Unneeded),
897897
start_pos,

0 commit comments

Comments
 (0)