Skip to content

Conversation

EvanHahn
Copy link

@EvanHahn EvanHahn commented Sep 9, 2021

Each iteration value in Set.prototype.entries() is an array of two identical values:

const mySet = new Set(['a' , 'b', 'c']);
console.log([...mySet.entries()]);
// => [ [ 'a', 'a' ], [ 'b', 'b' ], [ 'c', 'c' ] ]

That's unnecessary for this library, which can just use Set.prototype.values().

const mySet = new Set(['a' , 'b', 'c']);
console.log([...mySet.values()]);
// => [ 'a', 'b', 'c' ]

This simplifies the code a bit and should result in a small speed improvement.

Each iteration value in [`Set.prototype.entries()`][0] is an array of
two identical values:

    const mySet = new Set(['a' , 'b', 'c']);
    console.log([...mySet.entries()]);
    // => [ [ 'a', 'a' ], [ 'b', 'b' ], [ 'c', 'c' ] ]

That's unnecessary for this library, which can just use
[`Set.prototype.values()`][1].

    const mySet = new Set(['a' , 'b', 'c']);
    console.log([...mySet.values()]);
    // => [ 'a', 'b', 'c' ]

This simplifies the code a bit and should result in a small speed
improvement.

[0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values
@EvanHahn
Copy link
Author

Let me know if there's anything I can do to help this PR along.

@EvanHahn
Copy link
Author

This PR has been open for two years. Anything I can do to help get this merged?

@master-elodin
Copy link

sorry this hasn't been merged yet (if I had any power I would), but it did help me out a lot. thanks!

@epoberezkin
Copy link
Owner

I am wondering why it was entries to begin with, but values should do the same for sets

@EvanHahn
Copy link
Author

EvanHahn commented Jun 1, 2025

My guess: it was copied from the code for Map, which uses entries().

I don't think it's a runtime compatibility thing because everywhere entries() is supported, values() is supported too.

I ran a quick test on my machine, and this branch checks Sets about 22% faster. See the full code and results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants