Skip to content

Reduce some allocations #5748

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 19 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
else {
val newpd: this.type =
if (mySpan.isSynthetic) {
if (!mySpan.exists && span.exists)
if (!mySpan.exists && span.exists) {
envelope(source, span.startPos) // fill in children spans
() // Note: the `()` is there to prevent some inefficient code from being generated.
// Without it we get an allocation of a span here since the result type of the `if`
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this changes whether an allocation happens or not but it does make the code more efficient, I've opened an issue to track this that you could refer to in this comment: #5750

// is `Any`, the lub of `Span` and `Unit`.
}
this
}
else cloneIn(source)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ object Names {
*/
def termName(cs: Array[Char], offset: Int, len: Int): SimpleName = synchronized {
util.Stats.record("termName")
val h = hashValue(cs, offset, len) & (table.size - 1)
val h = hashValue(cs, offset, len) & (table.length - 1)

/** Make sure the capacity of the character array is at least `n` */
def ensureCapacity(n: Int) =
Expand Down