File tree 2 files changed +8
-8
lines changed
2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 132
132
} ) ;
133
133
equal ( upper ( 'foo' ) , 'FOO' ) ;
134
134
equal ( upper ( 'bar' ) , 'BAR' ) ;
135
- deepEqual ( upper . cache , { foo : 'FOO' , bar : 'BAR' } ) ;
136
- upper . cache = { foo : 'BAR' , bar : 'FOO' } ;
135
+ equal ( upper . cache . get ( 'foo' ) , 'FOO' ) ;
136
+ equal ( upper . cache . get ( 'bar' ) , 'BAR' ) ;
137
+ upper . cache . set ( 'foo' , 'BAR' ) ;
137
138
equal ( upper ( 'foo' ) , 'BAR' ) ;
138
- equal ( upper ( 'bar' ) , 'FOO' ) ;
139
139
140
140
var hashed = _ . memoize ( function ( key ) {
141
141
//https://github.com/jashkenas/underscore/pull/1679#discussion_r13736209
145
145
return key . toUpperCase ( ) ;
146
146
} ) ;
147
147
hashed ( 'yep' ) ;
148
- deepEqual ( hashed . cache , { 'YEP' : 'yep' } , 'takes a hasher' ) ;
148
+ equal ( hashed . cache . get ( 'YEP' ) , 'yep' , 'takes a hasher' ) ;
149
149
150
150
// Test that the hash function can be used to swizzle the key.
151
151
var objCacher = _ . memoize ( function ( value , key ) {
Original file line number Diff line number Diff line change 789
789
_ . memoize = function ( func , hasher ) {
790
790
var memoize = function ( key ) {
791
791
var cache = memoize . cache ;
792
- var address = '' + ( hasher ? hasher . apply ( this , arguments ) : key ) ;
793
- if ( ! _ . has ( cache , address ) ) cache [ address ] = func . apply ( this , arguments ) ;
794
- return cache [ address ] ;
792
+ var address = hasher ? hasher . apply ( this , arguments ) : key ;
793
+ if ( ! cache . has ( address ) ) cache . set ( address , func . apply ( this , arguments ) ) ;
794
+ return cache . get ( address ) ;
795
795
} ;
796
- memoize . cache = { } ;
796
+ memoize . cache = new Map ( ) ;
797
797
return memoize ;
798
798
} ;
799
799
You can’t perform that action at this time.
0 commit comments