File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -60,15 +60,23 @@ function objectContains(partial, object) {
6060 * @returns {* }
6161 */
6262function hasApproxPattern ( word , pattern ) {
63- if ( pattern === '' )
64- return word ;
65-
66- var index = word . indexOf ( pattern . charAt ( 0 ) ) ;
67-
68- if ( index === - 1 )
69- return false ;
70-
71- return hasApproxPattern ( word . substr ( index + 1 ) , pattern . substr ( 1 ) )
63+ // cheaper version of indexOf; instead of creating each
64+ // iteration new str.
65+ function indexOf ( word , p , c ) {
66+ var j = 0 ;
67+ while ( ( p + j ) <= word . length ) {
68+ if ( word . charAt ( p + j ) == c ) return j ;
69+ j ++ ;
70+ }
71+ return - 1 ;
72+ }
73+ var p = 0 ;
74+ for ( var i = 0 ; i <= pattern . length ; i ++ ) {
75+ var index = indexOf ( word , p , pattern . charAt ( i ) ) ;
76+ if ( index == - 1 ) return false ;
77+ p += index ;
78+ }
79+ return true
7280}
7381
7482/**
You can’t perform that action at this time.
0 commit comments