Skip to content

Commit

Permalink
optimize get_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Nov 19, 2024
1 parent d86df7d commit 7a98040
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions parser/src/earley/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,17 @@ impl ParserState {
for idx in 0..self.row_infos.len() {
let ri = &self.row_infos[idx];
trace!(" lexeme: {}", self.lexer_spec().dbg_lexeme(&ri.lexeme));
let mut bytes = ri.lexeme.visible_bytes().to_vec();
let mut bytes = ri.lexeme.visible_bytes();
let mut _tmp_bytes = vec![];
if bytes.is_empty() && idx == self.num_rows() - 1 {
bytes = self.curr_row_bytes();
_tmp_bytes = self.curr_row_bytes();
bytes = &_tmp_bytes;
trace!(" bytes: {:?}", String::from_utf8_lossy(&bytes));
};
self.row_infos[idx].start_byte_idx = allbytes.len();
let l = allbytes.len();
indices.extend((0..bytes.len()).map(|_| idx));
allbytes.extend_from_slice(&bytes);
self.row_infos[idx].start_byte_idx = l;
}
(indices, allbytes)
}
Expand Down

0 comments on commit 7a98040

Please sign in to comment.