-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Taking into account that `settings` is of type `Array[String]`, there is no need to convert `settings` to array.
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.
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 |
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.
This was probably intended, as it creates a new Array
making sure that it cannot be modified from outside the ReplDriver
.
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.
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
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.
@felixmulder Did you intend to make a copy?
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.
Nope, I think this is a remnant from when the ReplDriver
didn't take an array.
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.
Great.
Btw, I have just signed the CLA.
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.
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 :)
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.
I confirm that the CLA is signed. I need to figure out what's wrong with the dotty-bot
Taking into account that
settings
is of typeArray[String]
, there is no need to convertsettings
to array.