File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change 32
32
nativeKeys = Object . keys ,
33
33
nativeBind = FuncProto . bind ;
34
34
35
+
35
36
// Create a safe reference to the Underscore object for use below.
36
37
var _ = function ( obj ) {
37
38
if ( obj instanceof _ ) return obj ;
50
51
} else {
51
52
root . _ = _ ;
52
53
}
54
+
55
+ var InternalSet = root . Set ;
56
+ // Not even close to a Set shim
57
+ if ( typeof InternalSet != 'function' ) {
58
+ InternalSet = function FakeSet ( ) {
59
+ this . data = [ ] ;
60
+ } ;
61
+ InternalSet . prototype . add = function ( x ) {
62
+ this . data . push ( x ) ;
63
+ } ;
64
+ InternalSet . prototype . has = function ( x ) {
65
+ return _ . indexOf ( this . data , x ) >= 0 ;
66
+ } ;
67
+ }
53
68
54
69
// Current version.
55
70
_ . VERSION = '1.7.0' ;
505
520
}
506
521
if ( iteratee != null ) iteratee = _ . iteratee ( iteratee , context ) ;
507
522
var result = [ ] ;
508
- var seen = [ ] ;
523
+ var seen = isSorted ? null : new InternalSet ( ) ;
509
524
for ( var i = 0 , length = array . length ; i < length ; i ++ ) {
510
525
var value = array [ i ] ,
511
526
computed = iteratee ? iteratee ( value , i , array ) : value ;
512
527
if ( isSorted ) {
513
528
if ( ! i || seen !== computed ) result . push ( value ) ;
514
529
seen = computed ;
515
- } else if ( iteratee ) {
516
- if ( ! _ . contains ( seen , computed ) ) {
517
- seen . push ( computed ) ;
518
- result . push ( value ) ;
519
- }
520
- } else if ( ! _ . contains ( result , value ) ) {
530
+ } else if ( ! seen . has ( computed ) ) {
531
+ seen . add ( computed ) ;
521
532
result . push ( value ) ;
522
533
}
523
534
}
You can’t perform that action at this time.
0 commit comments