Faster testing against first char in stringToPath (to close #3308).

This commit is contained in:
Michał Lipiński
2017-08-14 10:27:49 +02:00
parent 03e23ecc19
commit 8e631dfcd4

View File

@@ -1,7 +1,7 @@
import memoizeCapped from './memoizeCapped.js' import memoizeCapped from './memoizeCapped.js'
const charCodeOfDot = '.'.charCodeAt(0)
const reEscapeChar = /\\(\\)?/g const reEscapeChar = /\\(\\)?/g
const reLeadingDot = /^\./
const rePropName = RegExp( const rePropName = RegExp(
// Match anything that isn't a dot or bracket. // Match anything that isn't a dot or bracket.
'[^.[\\]]+' + '|' + '[^.[\\]]+' + '|' +
@@ -25,7 +25,7 @@ const rePropName = RegExp(
*/ */
const stringToPath = memoizeCapped((string) => { const stringToPath = memoizeCapped((string) => {
const result = [] const result = []
if (reLeadingDot.test(string)) { if (string.charCodeAt(0) === charCodeOfDot) {
result.push('') result.push('')
} }
string.replace(rePropName, (match, expression, quote, subString) => { string.replace(rePropName, (match, expression, quote, subString) => {