Skip to content

Don't create a new TreeSet if there is no change to the underlying tree#8737

Merged
retronym merged 2 commits intoscala:2.12.xfrom
mkeskells:2.12.x_sortedSet-1
Feb 26, 2020
Merged

Don't create a new TreeSet if there is no change to the underlying tree#8737
retronym merged 2 commits intoscala:2.12.xfrom
mkeskells:2.12.x_sortedSet-1

Conversation

@mkeskells
Copy link
Contributor

No description provided.

@scala-jenkins scala-jenkins added this to the 2.12.12 milestone Feb 21, 2020
@diesalbla diesalbla added the library:collections PRs involving changes to the standard collection library label Feb 22, 2020
Copy link
Member

@retronym retronym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good backport idea. Safe and worthwhile for 2.12.11 (but I'd leave @lrytz to decide to merge)

@retronym retronym added the performance the need for speed. usually compiler performance, sometimes runtime performance. label Feb 26, 2020
@retronym retronym modified the milestones: 2.12.12, 2.12.11 Feb 26, 2020
/** A factory to create empty sets of the same type of keys.
*/
override def empty = TreeSet.empty
override def empty = newSet(null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you want to create a new instance every time instead of reusing the TreeSet.empty singleton?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TreeSet isn't a singleton, it has the implicit ordering parameter so creates a new instance
newSet will not create a new Set if this is already empty, and that is the best that we can do as I see it
def empty[A](implicit ordering: Ordering[A]) = new TreeSet[A]

@retronym retronym merged commit 90bc6cf into scala:2.12.x Feb 26, 2020
@SethTisue SethTisue changed the title Dont create a new TreeSet if there is no change to the underlying tree Don't create a new TreeSet if there is no change to the underlying tree Mar 9, 2020
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
Dont create a new TreeSet if there is no change to the underlying tree
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
Dont create a new TreeSet if there is no change to the underlying tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

library:collections PRs involving changes to the standard collection library performance the need for speed. usually compiler performance, sometimes runtime performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants