Skip to content

Commit

Permalink
Use iterables directly instead of using .values()
Browse files Browse the repository at this point in the history
This change should have no user impact.

This replaces the use of `Array.prototype.values()` and
`Set.prototype.values()` with the iterables themselves, as `.values()`
is redundant. To quote [MDN's docs][0]:

> `Array.prototype.values()` is the default implementation of
> `Array.prototype[@@iterator]()`.

MDN [says something similar for `Set`][1].

`git grep -F '.values()'` returns no results after this change.

[0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values#description
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/@@iterator#return_value
  • Loading branch information
EvanHahn committed Jan 16, 2024
1 parent 340fe31 commit de7ac40
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion benchmarks/multifeed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function createCores(multi, count) {
async function generateFixtures(cores, count) {
/** @type {Entry[]} */
const entries = []
for (const core of cores.values()) {
for (const core of cores) {
const offset = core.length
const blocks = generateFixture(offset, offset + count)
await promisify(core.append.bind(core))(blocks)
Expand Down
2 changes: 1 addition & 1 deletion lib/core-index-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class CoreIndexStream extends Readable {
}
// Still space in the read buffer? Process any downloaded blocks
if (this.#readBufferAvailable) {
for (const index of this.#downloaded.values()) {
for (const index of this.#downloaded) {
this.#downloaded.delete(index)
didPush =
(await this[kPushEntry](index)) ||
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function generateFixture(start, end) {
async function generateFixtures(cores, count) {
/** @type {Entry[]} */
const entries = []
for (const core of cores.values()) {
for (const core of cores) {
const offset = core.length
const blocks = generateFixture(offset, offset + count)
await core.append(blocks)
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/multi-core-index-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ test('Appends from a replicated core are indexed', async (t) => {
t.same(sortEntries(entries), sortEntries(expected1))

const expected2 = await generateFixtures(localCores, 50)
for (const remote of remoteCores.values()) {
for (const remote of remoteCores) {
remote.download({ start: 0, end: remote.length })
}
await throttledDrain(stream)
Expand Down

0 comments on commit de7ac40

Please sign in to comment.