Skip to content

Commit 3b2ba59

Browse files
committed
Use ArrayString instead of hand rolled data structure
1 parent e37ba70 commit 3b2ba59

File tree

5 files changed

+6
-39
lines changed

5 files changed

+6
-39
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_syntax/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = "Comment and whitespace preserving parser for the Rust langauge"
88
repository = "https://github.com/rust-analyzer/rust-analyzer"
99

1010
[dependencies]
11+
arrayvec = "0.4.7"
1112
unicode-xid = "0.1.0"
1213
itertools = "0.7.8"
1314
drop_bomb = "0.1.4"

crates/ra_syntax/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![allow(missing_docs)]
2121
//#![warn(unreachable_pub)] // rust-lang/rust#47816
2222

23+
extern crate arrayvec;
2324
extern crate drop_bomb;
2425
extern crate itertools;
2526
extern crate parking_lot;

crates/ra_syntax/src/utils.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent};
22
use std::fmt::Write;
3-
use std::ops::Deref;
43
use std::str;
54

65
/// 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) {
8079
}
8180
}
8281
}
83-
84-
#[derive(Debug)]
85-
pub struct MutAsciiString<'a> {
86-
buf: &'a mut [u8],
87-
len: usize,
88-
}
89-
90-
impl<'a> MutAsciiString<'a> {
91-
pub fn new(buf: &'a mut [u8]) -> MutAsciiString<'a> {
92-
MutAsciiString { buf, len: 0 }
93-
}
94-
95-
pub fn as_str(&self) -> &str {
96-
str::from_utf8(&self.buf[..self.len]).unwrap()
97-
}
98-
99-
pub fn len(&self) -> usize {
100-
self.len
101-
}
102-
103-
pub fn push(&mut self, c: char) {
104-
assert!(self.len() < self.buf.len());
105-
assert!(c.is_ascii());
106-
107-
self.buf[self.len] = c as u8;
108-
self.len += 1;
109-
}
110-
}
111-
112-
impl<'a> Deref for MutAsciiString<'a> {
113-
type Target = str;
114-
fn deref(&self) -> &str {
115-
self.as_str()
116-
}
117-
}

crates/ra_syntax/src/validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::u32;
22

3+
use arrayvec::ArrayString;
4+
35
use crate::{
46
algo::visit::{visitor_ctx, VisitorCtx},
57
ast::{self, AstNode},
68
File,
79
string_lexing::{self, CharComponentKind},
8-
utils::MutAsciiString,
910
yellow::{
1011
SyntaxError,
1112
SyntaxErrorKind::*,
@@ -76,8 +77,7 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
7677
return;
7778
}
7879

79-
let mut buf = &mut [0; 6];
80-
let mut code = MutAsciiString::new(buf);
80+
let mut code = ArrayString::<[_; 6]>::new();
8181
let mut closed = false;
8282
for c in text[3..].chars() {
8383
assert!(!closed, "no characters after escape is closed");

0 commit comments

Comments
 (0)