Skip to content

Commit

Permalink
{refactor} rewrite string post-processing
Browse files Browse the repository at this point in the history
This rewrite makes use of more regular expressions and more complex regular expressions
but this complexity buys us a few things:

First up, String#split is slow. Replacing those with regular expression tests improves
our benchmark from 30k docs/sec to 33k docs/sec on my current device.

Next up, by processing all escapes in a single go we can tie invalid escapes to their
exact locations in the string. This makes it possible to highlight multiple errors in
a single string in a useful manner.
  • Loading branch information
bgotink committed Jan 7, 2025
1 parent 2f5465f commit b6f275d
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 142 deletions.
8 changes: 4 additions & 4 deletions src/format.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {InvalidKdlError} from "./index.js";
import {Document, Entry, Identifier, Node, Tag, Value} from "./model.js";
import {
isValidBareIdentifier,
reStartsWithInlineWhitespace,
} from "./string-utils.js";
import {isValidBareIdentifier} from "./string-utils.js";

const reStartsWithInlineWhitespace =
/^[\uFEFF\u0009\u0020\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/;

/**
* @param {Tag | null} tag
Expand Down
Loading

0 comments on commit b6f275d

Please sign in to comment.