Skip to content

Commit

Permalink
fix: fix #19 (improve parsing performance)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbouvrette committed Oct 11, 2023
1 parent 24c37ab commit 1b2ef59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Just like Java, if a Unicode-escaped character (`\u`) is malformed, an error wil

## Additional references

- Java [Test Sandbox](https://codehs.com/sandbox/id/java-main-uSOlNK)
- Java [Test Sandbox](https://codehs.com/sandbox/id/java-main-FObePj)
- Java's `Properties` class [documentation](https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html)
- Java's `PropertyResourceBundle` [documentation](https://docs.oracle.com/javase/9/docs/api/java/util/PropertyResourceBundle.html)
- Java's Internationalization [Guide](https://docs.oracle.com/en/java/javase/18/intl/internationalization-overview.html)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"eslint-plugin-jest": "27.4.2",
"eslint-plugin-json-files": "3.0.0",
"eslint-plugin-prefer-arrow-functions": "3.1.4",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-prettier": "5.0.1",
"eslint-plugin-tsdoc": "0.2.17",
"eslint-plugin-unicorn": "48.0.1",
"jest": "29.7.0",
Expand Down
30 changes: 11 additions & 19 deletions src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,19 @@ export class Property {
return
}

for (
let character = this.linesContent[0], position = 0;
position < this.linesContent.length;
position++, character = this.linesContent[position]
) {
// If the character is not a separator, check the next one.
if (!/[\t\f :=]/.test(character)) {
continue
}
// Only match separators to avoid iterating all characters.
for (const match of this.linesContent.matchAll(/[\t\f :=]/g)) {
const position = match.index!

// Check if the separator might be escaped.
const prefix = position ? this.linesContent.slice(0, position) : ''

if (prefix.length > 0) {
const backslashMatch = prefix.match(/(?<backslashes>\\+)$/)
if (backslashMatch?.groups) {
const separatorIsEscaped = !!(backslashMatch.groups.backslashes.length % 2)
if (separatorIsEscaped) {
// If the separator is escaped, check the next character.
continue
}
const prefix = this.linesContent.slice(0, position)
const backslashMatch = prefix.match(/(?<backslashes>\\+)$/)

if (backslashMatch?.groups) {
const separatorIsEscaped = !!(backslashMatch.groups.backslashes.length % 2)
if (separatorIsEscaped) {
// If the separator is escaped, check the next character.
continue
}
}

Expand Down

0 comments on commit 1b2ef59

Please sign in to comment.