Skip to content

Commit

Permalink
Speed up pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Mar 21, 2016
1 parent 90ceb42 commit 6e908b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions modules/PatternUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ function _compilePattern(pattern) {
regexpSource += '([^/?#]+)'
paramNames.push(match[1])
} else if (match[0] === '**') {
regexpSource += '([\\s\\S]*)'
regexpSource += '(.*)'
paramNames.push('splat')
} else if (match[0] === '*') {
regexpSource += '([\\s\\S]*?)'
regexpSource += '(.*?)'
paramNames.push('splat')
} else if (match[0] === '(') {
regexpSource += '(?:'
Expand Down Expand Up @@ -98,8 +98,7 @@ export function matchPattern(pattern, pathname) {
const captureRemaining = tokens[tokens.length - 1] !== '*'

if (captureRemaining) {
// This will match newlines in the remaining path.
regexpSource += '([\\s\\S]*?)'
regexpSource += '(.*?)'
}

const match = pathname.match(new RegExp('^' + regexpSource + '$', 'i'))
Expand Down
2 changes: 1 addition & 1 deletion modules/__tests__/getParams-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('getParams', function () {
expect(getParams('/files/*', '/files/my/photo.jpg')).toEqual({ splat: 'my/photo.jpg' })
expect(getParams('/files/*', '/files/my/photo.jpg.zip')).toEqual({ splat: 'my/photo.jpg.zip' })
expect(getParams('/files/*.jpg', '/files/my/photo.jpg')).toEqual({ splat: 'my/photo' })
expect(getParams('/files/*.jpg', '/files/my/new\nline.jpg')).toEqual({ splat: 'my/new\nline' })
expect(getParams('/files/*.jpg', '/files/my/new%0Aline.jpg')).toEqual({ splat: 'my/new\nline' })
})
})

Expand Down

0 comments on commit 6e908b5

Please sign in to comment.