Skip to content

Commit ad5aeb4

Browse files
authored
Faster and implementation of some (immutable-js#1944)
1 parent 6e0720c commit ad5aeb4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

perf/List.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,14 @@ describe('List', function () {
100100
list = list.asImmutable();
101101
});
102102
});
103+
104+
describe('some', function () {
105+
it('100 000 items ', () => {
106+
const list = Immutable.List();
107+
for (let i = 0; i < 100000; i++) {
108+
list.push(i);
109+
}
110+
list.some(item => item === 50000);
111+
});
112+
});
103113
});

src/CollectionImpl.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,15 @@ mixin(Collection, {
266266
},
267267

268268
some(predicate, context) {
269-
return !this.every(not(predicate), context);
269+
assertNotInfinite(this.size);
270+
let returnValue = false;
271+
this.__iterate((v, k, c) => {
272+
if (predicate.call(context, v, k, c)) {
273+
returnValue = true;
274+
return false;
275+
}
276+
});
277+
return returnValue;
270278
},
271279

272280
sort(comparator) {

0 commit comments

Comments
 (0)