Skip to content

Remove redundant conversion of settings to array #3384

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 1 commit into from
Oct 26, 2017
Merged
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ReplDriver(settings: Array[String],
/** Create a fresh and initialized context with IDE mode enabled */
private[this] def initialCtx = {
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
val ictx = setup(settings.toArray, rootCtx)._2.fresh
val ictx = setup(settings, rootCtx)._2.fresh
Copy link
Contributor

Choose a reason for hiding this comment

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

This was probably intended, as it creates a new Array making sure that it cannot be modified from outside the ReplDriver.

Copy link
Contributor

Choose a reason for hiding this comment

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

toArray does not create a new Array:

scala> val foo = Array(1 , 2)
foo: Array[Int] = Array(1, 2)

scala> foo eq foo.toArray
res0: Boolean = true

Copy link
Contributor

Choose a reason for hiding this comment

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

@felixmulder Did you intend to make a copy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, I think this is a remnant from when the ReplDriver didn't take an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great.
Btw, I have just signed the CLA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have checked the classes involved in processing settings and have not found any mutation of the array, only conversion to list in CompilerCommand. Shall I defend the array from potential yet no existing side-effects by making a copy ? Seems like premature optimisation to me, but you decide :)

ictx.base.initialize()(ictx)
ictx
}
Expand Down