Skip to content

update Lib.sort comment and relax its tests #3124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ exports.roundUp = function(val, arrayIn, reverse) {
/**
* Tweak to Array.sort(sortFn) that improves performance for pre-sorted arrays
*
* Note that newer browsers (such as Chrome v70+) are starting to pick up
* on pre-sorted arrays which may render the following optimization unnecessary
* in the future.
*
* Motivation: sometimes we need to sort arrays but the input is likely to
* already be sorted. Browsers don't seem to pick up on pre-sorted arrays,
* and in fact Chrome is actually *slower* sorting pre-sorted arrays than purely
Expand Down
8 changes: 0 additions & 8 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2329,21 +2329,13 @@ describe('Test lib.js:', function() {
.toEqual(dupes());

expect(callCount).toEqual(18);

callCount = 0;
dupes().sort(sortCounter);
expect(callCount).toBeGreaterThan(18);
});

it('still short-circuits reversed with duplicates', function() {
expect(_sort(dupes(), sortCounterReversed))
.toEqual(dupes().reverse());

expect(callCount).toEqual(18);

callCount = 0;
dupes().sort(sortCounterReversed);
expect(callCount).toBeGreaterThan(18);
});
});

Expand Down