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

Conversation

nerush
Copy link
Contributor

@nerush nerush commented Oct 25, 2017

Taking into account that settings is of type Array[String], there is no need to convert settings to array.

Taking into account that `settings` is of type `Array[String]`, there is no need to convert `settings` to array.
Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@@ -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 :)

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

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

I confirm that the CLA is signed. I need to figure out what's wrong with the dotty-bot

@allanrenucci allanrenucci merged commit b3e3999 into scala:master Oct 26, 2017
@nerush nerush deleted the patch-1 branch October 26, 2017 09:52
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.

5 participants