Skip to content

Commit 27f0283

Browse files
committed
Updated from review
1 parent 75effe4 commit 27f0283

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

Source/Core/Heap.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ function Heap(options) {
2424
this._maximumLength = undefined;
2525
}
2626

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-
3727
Object.defineProperties(Heap.prototype, {
3828
/**
3929
* Gets the length of the heap.
@@ -75,12 +65,17 @@ Object.defineProperties(Heap.prototype, {
7565
return this._maximumLength;
7666
},
7767
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+
}
8175
this._length = value;
82-
this._array.length = value;
76+
array.length = value;
8377
}
78+
this._maximumLength = value;
8479
},
8580
},
8681

Source/Core/ManagedArray.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ function ManagedArray(length) {
1616
this._length = length;
1717
}
1818

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-
2919
Object.defineProperties(ManagedArray.prototype, {
3020
/**
3121
* Gets or sets the length of the array.
@@ -39,10 +29,15 @@ Object.defineProperties(ManagedArray.prototype, {
3929
return this._length;
4030
},
4131
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;
4641
}
4742
},
4843
},

0 commit comments

Comments
 (0)