File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const benchmark = require ( 'benchmark' )
2+ const AKM = require ( '../main.js' )
3+
4+ const letters = 'abcdefghijklmnopqrstuvwxyz' . split ( '' )
5+
6+ const lettersMap = new AKM ( )
7+ for ( const x of letters ) lettersMap . set ( Array ( 100 ) . fill ( x ) , true )
8+
9+ new benchmark . Suite ( )
10+ . add ( '100-item hasPrefix' , ( ) => {
11+ for ( const x of letters ) lettersMap . hasPrefix ( Array ( 100 ) . fill ( x ) )
12+ } )
13+ . on ( 'cycle' , ev => console . log ( String ( ev . target ) ) )
14+ . run ( )
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ class ArrayKeyedMap {
7878 this . _size = 0
7979 }
8080
81- hasPrefix ( path ) { return hasPrefix ( path , this . _root , this ) }
81+ hasPrefix ( path ) { return hasPrefix . call ( this , path ) }
8282
8383 get [ Symbol . toStringTag ] ( ) { return 'ArrayKeyedMap' }
8484
@@ -175,16 +175,13 @@ function del (path) {
175175 return hadPreviousValue
176176}
177177
178- const hasPrefix = ( path , store ) => {
179- switch ( path . length ) {
180- case 0 :
181- return true
182- default : {
183- const [ next , ...rest ] = path
184- const nextStore = store . get ( next )
185- return nextStore ? hasPrefix ( rest , nextStore ) : false
186- }
178+ function hasPrefix ( path ) {
179+ let map = this . _root
180+ for ( const item of path ) {
181+ map = map . get ( item )
182+ if ( ! map ) return false
187183 }
184+ return true
188185}
189186
190187const entries = function * ( path , store ) {
You can’t perform that action at this time.
0 commit comments