Skip to content

Commit

Permalink
perf(projection-parser): improve performance by reorganizing parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Dec 24, 2018
1 parent 27dedef commit 5d74903
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/__tests__/__snapshots__/interpreter.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1905,9 +1905,9 @@ Object {
"value": Array [
Object {
"end": Object {
"column": 18,
"column": 20,
"line": 1,
"offset": 17,
"offset": 19,
},
"name": "simpleList",
"start": Object {
Expand Down Expand Up @@ -1983,9 +1983,9 @@ Object {
"value": Array [
Object {
"end": Object {
"column": 14,
"column": 15,
"line": 1,
"offset": 13,
"offset": 14,
},
"name": "simpleList",
"start": Object {
Expand Down Expand Up @@ -3842,9 +3842,9 @@ Object {
"value": Array [
Object {
"end": Object {
"column": 8,
"line": 5,
"offset": 80,
"column": 5,
"line": 6,
"offset": 85,
},
"name": "simpleList",
"start": Object {
Expand Down Expand Up @@ -3941,9 +3941,9 @@ Object {
"value": Array [
Object {
"end": Object {
"column": 33,
"line": 4,
"offset": 72,
"column": 7,
"line": 5,
"offset": 79,
},
"name": "simpleList",
"start": Object {
Expand Down
25 changes: 15 additions & 10 deletions src/parsers/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
ListNodeType,
ProjectionNodeType,
ValuePropNodeType,
ProjectableNodeType
ProjectableNodeType,
NodeType
} from '../types'

type WrappedProjectionNodeType =
Expand Down Expand Up @@ -82,15 +83,19 @@ const ProjectionParser = P.lazy((): mixed => {
packProperty
)

return P.alt(
P.seq(
ProjectableParser.skip(crap),
P.alt(ProjectionParser, PropertyParser)
.skip(crap)
.atLeast(1)
).map(unpack),
ProjectableParser
).desc('projection')
return P.seq(
ProjectableParser.skip(crap),
P.alt(ProjectionParser, PropertyParser)
.skip(crap)
.many()
)
.map(
([left, right]: [
ProjectableNodeType,
Array<WrappedProjectionNodeWithOptionalType>
]): NodeType => (right.length === 0 ? left : unpack([left, right]))
)
.desc('projection')
})

export default ProjectionParser

0 comments on commit 5d74903

Please sign in to comment.