File tree 2 files changed +18
-28
lines changed
2 files changed +18
-28
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,6 @@ function Heap(options) {
24
24
this . _maximumLength = undefined ;
25
25
}
26
26
27
- function removeTrailingReferences ( heap , newLength ) {
28
- var originalLength = heap . _length ;
29
- if ( newLength < originalLength ) {
30
- var array = heap . _array ;
31
- for ( var i = newLength ; i < originalLength ; ++ i ) {
32
- array [ i ] = undefined ;
33
- }
34
- }
35
- }
36
-
37
27
Object . defineProperties ( Heap . prototype , {
38
28
/**
39
29
* Gets the length of the heap.
@@ -75,12 +65,17 @@ Object.defineProperties(Heap.prototype, {
75
65
return this . _maximumLength ;
76
66
} ,
77
67
set : function ( value ) {
78
- removeTrailingReferences ( this , value ) ;
79
- this . _maximumLength = value ;
80
- if ( this . _length > value && value > 0 ) {
68
+ var originalLength = this . _length ;
69
+ if ( value < originalLength ) {
70
+ var array = this . _array ;
71
+ // Remove trailing references
72
+ for ( var i = value ; i < originalLength ; ++ i ) {
73
+ array [ i ] = undefined ;
74
+ }
81
75
this . _length = value ;
82
- this . _array . length = value ;
76
+ array . length = value ;
83
77
}
78
+ this . _maximumLength = value ;
84
79
} ,
85
80
} ,
86
81
Original file line number Diff line number Diff line change @@ -16,16 +16,6 @@ function ManagedArray(length) {
16
16
this . _length = length ;
17
17
}
18
18
19
- function removeTrailingReferences ( managedArray , newLength ) {
20
- var array = managedArray . _array ;
21
- var originalLength = managedArray . _length ;
22
- if ( newLength < originalLength ) {
23
- for ( var i = newLength ; i < originalLength ; ++ i ) {
24
- array [ i ] = undefined ;
25
- }
26
- }
27
- }
28
-
29
19
Object . defineProperties ( ManagedArray . prototype , {
30
20
/**
31
21
* Gets or sets the length of the array.
@@ -39,10 +29,15 @@ Object.defineProperties(ManagedArray.prototype, {
39
29
return this . _length ;
40
30
} ,
41
31
set : function ( length ) {
42
- removeTrailingReferences ( this , length ) ;
43
- this . _length = length ;
44
- if ( length > this . _array . length ) {
45
- this . _array . length = length ;
32
+ var array = this . _array ;
33
+ var originalLength = this . _length ;
34
+ if ( length < originalLength ) {
35
+ // Remove trailing references
36
+ for ( var i = length ; i < originalLength ; ++ i ) {
37
+ array [ i ] = undefined ;
38
+ }
39
+ } else if ( length > array . length ) {
40
+ array . length = length ;
46
41
}
47
42
} ,
48
43
} ,
You can’t perform that action at this time.
0 commit comments