Skip to content

Commit

Permalink
perf: small performance improvement avoiding Array#unshift
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Oct 9, 2020
1 parent 1dd6ec5 commit 84f5245
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/feedsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ module.exports = class FeedReader extends EventEmitter {
const success = (abort) => {
if (ended) { return; }
ended = true;
if (sortOrder <= 0) {
newItems.reverse();
}
this.news.addHistory('item', newItems.map((item) => [item]));
if (this.first && !this.options.emitOnStart) {
newItems = [];
Expand Down Expand Up @@ -260,11 +263,11 @@ module.exports = class FeedReader extends EventEmitter {

const getOlderItem = (item) => {
if (this.first) {
newItems.unshift(item);
newItems.push(item);
} else if (!ended) {
let emitted = this.news.emit('item', item);
if (emitted) {
newItems.unshift(item);
newItems.push(item);
} else {
// Check if this item has already been read in previous requests
// if it has, then stop parsing the rest of the document.
Expand Down

0 comments on commit 84f5245

Please sign in to comment.