mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Use ArrayString instead of hand rolled data structure
This commit is contained in:
parent
e37ba706cc
commit
3b2ba59526
5 changed files with 6 additions and 39 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -671,6 +671,7 @@ dependencies = [
|
|||
name = "ra_syntax"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -8,6 +8,7 @@ description = "Comment and whitespace preserving parser for the Rust langauge"
|
|||
repository = "https://github.com/rust-analyzer/rust-analyzer"
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.4.7"
|
||||
unicode-xid = "0.1.0"
|
||||
itertools = "0.7.8"
|
||||
drop_bomb = "0.1.4"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#![allow(missing_docs)]
|
||||
//#![warn(unreachable_pub)] // rust-lang/rust#47816
|
||||
|
||||
extern crate arrayvec;
|
||||
extern crate drop_bomb;
|
||||
extern crate itertools;
|
||||
extern crate parking_lot;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent};
|
||||
use std::fmt::Write;
|
||||
use std::ops::Deref;
|
||||
use std::str;
|
||||
|
||||
/// Parse a file and create a string representation of the resulting parse tree.
|
||||
|
@ -80,38 +79,3 @@ pub(crate) fn validate_block_structure(root: SyntaxNodeRef) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MutAsciiString<'a> {
|
||||
buf: &'a mut [u8],
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl<'a> MutAsciiString<'a> {
|
||||
pub fn new(buf: &'a mut [u8]) -> MutAsciiString<'a> {
|
||||
MutAsciiString { buf, len: 0 }
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
str::from_utf8(&self.buf[..self.len]).unwrap()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.len
|
||||
}
|
||||
|
||||
pub fn push(&mut self, c: char) {
|
||||
assert!(self.len() < self.buf.len());
|
||||
assert!(c.is_ascii());
|
||||
|
||||
self.buf[self.len] = c as u8;
|
||||
self.len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for MutAsciiString<'a> {
|
||||
type Target = str;
|
||||
fn deref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use std::u32;
|
||||
|
||||
use arrayvec::ArrayString;
|
||||
|
||||
use crate::{
|
||||
algo::visit::{visitor_ctx, VisitorCtx},
|
||||
ast::{self, AstNode},
|
||||
File,
|
||||
string_lexing::{self, CharComponentKind},
|
||||
utils::MutAsciiString,
|
||||
yellow::{
|
||||
SyntaxError,
|
||||
SyntaxErrorKind::*,
|
||||
|
@ -76,8 +77,7 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
|
|||
return;
|
||||
}
|
||||
|
||||
let mut buf = &mut [0; 6];
|
||||
let mut code = MutAsciiString::new(buf);
|
||||
let mut code = ArrayString::<[_; 6]>::new();
|
||||
let mut closed = false;
|
||||
for c in text[3..].chars() {
|
||||
assert!(!closed, "no characters after escape is closed");
|
||||
|
|
Loading…
Reference in a new issue