Skip to content

EcmaScript lexer is inefficient #3

@kdy1

Description

@kdy1
  • It currently pushes one char at a time. It should chunk to amortize allocations.

Current code is similar to

let mut buf = String::new();
loop {
   // xxx
   buf.push(c);
}

Obviously, this almost always allocate and reallocates quite frequently.


  • It allocate needlessly while tokenizing numeric literals.

Noticeable parts are

let s = format!("{}", val);
// if it contains '8' or '9', it's decimal.
if s.contains('8') || s.contains('9') {}
// It's Legacy octal, and we should reinterpret value.
let val = u64::from_str_radix(&format!("{}", val), 8)
    .expect("Does this can really happen?");
let val = format!("{}", val)
    .parse()
     .expect("failed to parse numeric value as f64");
val = format!("{}.{}", val, minority).parse();

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions