-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use String as the SourceFile content type #26846
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
5175710
6fe6442
0e404a3
243d057
b17aab4
83f2954
9a27a7c
30f00c6
6fd3877
35092d4
4cd7f76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,9 +196,9 @@ object NameOps { | |
| } | ||
| } | ||
|
|
||
| /** Do two target names match? An empty target name matchws any other name. */ | ||
| /** Do two target names match? An empty target name matches any other name. */ | ||
| def matchesTargetName(other: Name) = | ||
| name == other || name.isEmpty || other.isEmpty | ||
| name.isEmpty || other.isEmpty || name == other | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor but alongside the other targetName change, noticed while profiling, this order seems to make more sense to avoid calling into string equality if we can |
||
|
|
||
| private def functionSuffixStart: Int = | ||
| val first = name.firstPart | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,18 @@ object PositionPickler: | |
|
|
||
| /** Pickle the number of lines followed by the size of each line */ | ||
| def pickleLinesSizes(): Unit = { | ||
| val content = source.content() | ||
| buf.writeNat(content.count(_ == '\n') + 1) // number of lines | ||
| val content = source.textContent() | ||
| // Inlined and simplified version of `count` because this is hot, | ||
| // and we can't have the optimizer inline the stdlib into the compiler as it may run under a different stdlib. | ||
| // Note that we start at 1 since #lines = #separators + 1. | ||
| var lineCount = 1 | ||
| var idx = -1 | ||
| while | ||
| idx = content.indexOf('\n', idx + 1) | ||
| idx != -1 | ||
| do | ||
| lineCount += 1 | ||
| buf.writeNat(lineCount) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one comes from Haoyi's pickling-related perf PR. (I did not make the other changes to this function from that PR, namely inlining |
||
| var lastIndex = content.indexOf('\n') | ||
| buf.writeNat(if lastIndex != -1 then lastIndex else content.length) // size of first line | ||
| while lastIndex != -1 do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1853,7 +1853,7 @@ class TreeUnpickler(reader: TastyReader, | |
| */ | ||
| def sourceChangeContext(addr: Addr = currentAddr)(using Context): Context = { | ||
| val path = sourcePathAt(addr) | ||
| if (path.nonEmpty) { | ||
| if (!path.isEmpty) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nonEmpty is a Scala extension |
||
| val sourceFile = ctx.getSource(path) | ||
| posUnpicklerOpt match | ||
| case Some(posUnpickler) if !sourceFile.initialized => | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmarking and profiling this PR turned into a general "let me look at what String-related stuff pops up" exercise.
We can't inline
StringOpsbecause the compiler might run with a different standard library.Also, IMHO, it's weird to use
++on strings when we're not explicitly looking at them as sequences of characters.