Skip to content

Commit

Permalink
Merge pull request #439 from markw65/faster-pos-details
Browse files Browse the repository at this point in the history
Make peg$computePosDetails a little faster
  • Loading branch information
hildjj authored Dec 9, 2023
2 parents fe34d94 + 7c1c759 commit f2c271f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Released: TBD

### Minor Changes

- [#439](https://github.com/peggyjs/peggy/pull/439) Make peg$computePosDetails a little faster
- [#437](https://github.com/peggyjs/peggy/pull/437) Better type checking for visitor
- [#435](https://github.com/peggyjs/peggy/pull/435) Setup tsconfig to detect use of library functions from es6 or later
- [#438](https://github.com/peggyjs/peggy/pull/438) Make test build deterministic
Expand Down
2 changes: 1 addition & 1 deletion docs/js/benchmark-bundle.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/js/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ function peg$parse(input, options) {
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
if (pos >= peg$posDetailsCache.length) {
p = peg$posDetailsCache.length - 1;
} else {
p = pos;
while (!peg$posDetailsCache[--p]) {}
}

details = peg$posDetailsCache[p];
Expand Down
2 changes: 1 addition & 1 deletion docs/js/test-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/vendor/peggy/peggy.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions lib/compiler/passes/generate-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,9 +1197,11 @@ function generateJS(ast, options) {
" if (details) {",
" return details;",
" } else {",
" p = pos - 1;",
" while (!peg$posDetailsCache[p]) {",
" p--;",
" if (pos >= peg$posDetailsCache.length) {",
" p = peg$posDetailsCache.length - 1;",
" } else {",
" p = pos;",
" while (!peg$posDetailsCache[--p]) {}",
" }",
"",
" details = peg$posDetailsCache[p];",
Expand Down
8 changes: 5 additions & 3 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,11 @@ function peg$parse(input, options) {
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
if (pos >= peg$posDetailsCache.length) {
p = peg$posDetailsCache.length - 1;
} else {
p = pos;
while (!peg$posDetailsCache[--p]) {}
}

details = peg$posDetailsCache[p];
Expand Down

0 comments on commit f2c271f

Please sign in to comment.