Skip to content

Commit

Permalink
Use Lrc<[u8]/str> instead of Lrc<Vec<u8>/String> in libsyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Apr 4, 2018
1 parent 5deed73 commit 8ac8ba6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ pub enum LitKind {
/// A string literal (`"foo"`)
Str(Symbol, StrStyle),
/// A byte string (`b"foo"`)
ByteStr(Lrc<Vec<u8>>),
ByteStr(Lrc<[u8]>),
/// A byte char (`b'f'`)
Byte(u8),
/// A character literal (`'a'`)
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/ext/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use util::small_vector::SmallVector;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
use rustc_data_structures::sync::Lrc;

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

base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes))))
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::from(bytes))))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct StringReader<'a> {
pub fatal_errs: Vec<DiagnosticBuilder<'a>>,
// cache a direct reference to the source text, so that we don't have to
// retrieve it via `self.filemap.src.as_ref().unwrap()` all the time.
source_text: Lrc<String>,
source_text: Lrc<str>,
/// Stack of open delimiters and their spans. Used for error message.
token: token::Token,
span: Span,
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub fn lit_token(lit: token::Lit, suf: Option<Symbol>, diag: Option<(Span, &Hand
(true, Some(LitKind::ByteStr(byte_str_lit(&i.as_str()))))
}
token::ByteStrRaw(i, _) => {
(true, Some(LitKind::ByteStr(Lrc::new(i.to_string().into_bytes()))))
(true, Some(LitKind::ByteStr(Lrc::from(i.as_str().as_bytes()))))
}
}
}
Expand Down Expand Up @@ -502,7 +502,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) {
}
}

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

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

Lrc::new(res)
Lrc::from(res)
}

pub fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>)
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ pub struct FileMap {
/// Indicates which crate this FileMap was imported from.
pub crate_of_origin: u32,
/// The complete source code
pub src: Option<Lrc<String>>,
pub src: Option<Lrc<str>>,
/// The source code's hash
pub src_hash: u128,
/// The external source code (used for external crates, which will have a `None`
Expand Down Expand Up @@ -891,7 +891,7 @@ impl FileMap {
name_was_remapped,
unmapped_path: Some(unmapped_path),
crate_of_origin: 0,
src: Some(Lrc::new(src)),
src: Some(Lrc::from(src)),
src_hash,
external_src: Lock::new(ExternalSource::Unneeded),
start_pos,
Expand Down

0 comments on commit 8ac8ba6

Please sign in to comment.