Skip to content

Commit 83137e4

Browse files
committed
performance revise
1 parent 3ebf9d7 commit 83137e4

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

src/javascript/multiplex.js

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -798,22 +798,22 @@
798798

799799

800800
$ensureType(factory, FUNCTION);
801-
$define(this, "next", {
802801

803-
/**
804-
* Advances the enumerator to the next element of the collection.
805-
* @returns {Boolean}
806-
*/
807-
value: function () {
808-
_current = undefined; // reset "current"
809-
_next = false; // reset "next"
810802

811-
factory(_yielder);
812-
this.current = _current;
803+
/**
804+
* Advances the enumerator to the next element of the collection.
805+
* @returns {Boolean}
806+
*/
813807

814-
return _next;
815-
}
816-
});
808+
this.next = function () {
809+
_current = undefined; // reset "current"
810+
_next = false; // reset "next"
811+
812+
factory(_yielder);
813+
this.current = _current;
814+
815+
return _next;
816+
};
817817

818818

819819
/**
@@ -856,12 +856,6 @@
856856
obj = obj || [];
857857

858858

859-
/// Enumerable object
860-
if ($is(obj, __Enumerable)) {
861-
return obj.getEnumerator();
862-
}
863-
864-
865859

866860
/// ES6/Legacy generator function
867861
if ($isFunc(obj)) {
@@ -884,6 +878,13 @@
884878

885879

886880

881+
/// Enumerator object
882+
if ($isFunc(obj.getEnumerator)) {
883+
return obj.getEnumerator();
884+
}
885+
886+
887+
887888
/// ES6 Iterable object: Map, Set and Iterable objects
888889
if ($isFunc(obj[_iteratorSymbol])) {
889890
var _iterator = obj[_iteratorSymbol](),
@@ -898,13 +899,6 @@
898899

899900

900901

901-
/// Enumerator object
902-
if ($isFunc(obj.getEnumerator)) {
903-
return obj.getEnumerator();
904-
}
905-
906-
907-
908902
/// Regular object
909903
return function () {
910904

@@ -1056,8 +1050,9 @@
10561050

10571051

10581052
function Comparer(comparison) {
1059-
$ensureType(comparison, FUNCTION);
1060-
$define(this, "_comparison", { value: comparison });
1053+
if ($isFunc(comparison)) {
1054+
$define(this, "compare", { value: comparison });
1055+
}
10611056
}
10621057

10631058
return $extend(Comparer,
@@ -1072,15 +1067,15 @@
10721067
* Greater than zero x is greater than y.
10731068
*/
10741069
compare: function (objA, objB) {
1075-
return this._comparison(objA, objB);
1070+
return $computeCompare(objA, objB);
10761071
}
10771072
},
10781073
{
10791074

10801075
/**
10811076
* Gets a default sort order comparer for the type specified by the generic argument.
10821077
*/
1083-
defaultComparer: new Comparer($computeCompare),
1078+
defaultComparer: new Comparer(),
10841079

10851080

10861081
/**
@@ -1102,11 +1097,13 @@
11021097

11031098
function EqualityComparer(hashCodeProvider, equality) {
11041099

1105-
$ensureType(equality, FUNCTION);
1106-
$ensureType(hashCodeProvider, FUNCTION);
1100+
if ($isFunc(equality)) {
1101+
$define(this, "equals", { value: equality });
1102+
}
11071103

1108-
$define(this, "_equality", { value: equality });
1109-
$define(this, "_hashCodeProvider", { value: hashCodeProvider });
1104+
if ($isFunc(hashCodeProvider)) {
1105+
$define(this, "hash", { value: hashCodeProvider });
1106+
}
11101107
}
11111108

11121109

@@ -1119,7 +1116,7 @@
11191116
* @returns true if the specified objects are equal; otherwise, false.
11201117
*/
11211118
equals: function (x, y) {
1122-
return this._equality(x, y);
1119+
return $computeEquals(x, y, true);
11231120
},
11241121

11251122
/**
@@ -1128,15 +1125,15 @@
11281125
* @returns A hash code for the specified object.
11291126
*/
11301127
hash: function (obj) {
1131-
return this._hashCodeProvider(obj);
1128+
return $computeHash(obj, true);
11321129
}
11331130
},
11341131
{
11351132

11361133
/**
11371134
* Gets a default equality comparer for the type specified by the generic argument.
11381135
*/
1139-
defaultComparer: new EqualityComparer($hash, $equals),
1136+
defaultComparer: new EqualityComparer(),
11401137

11411138
/**
11421139
* Creates an EqualityComparer by using the specified equality and hashCodeProvider.
@@ -1177,7 +1174,7 @@
11771174

11781175
var _source = $prop(this);
11791176

1180-
if(_source){
1177+
if (_source) {
11811178
return $count(_source);
11821179
}
11831180

0 commit comments

Comments
 (0)