-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Merge mutable.ArrayDeque into mutable.Buffer on the JVM
#25034
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?
Conversation
mutable.ArrayDeque into mutable.Buffermutable.ArrayDeque into mutable.Buffer on the JVM
9b303aa to
b173a61
Compare
|
the community build failure is benign and expected given the nature of the change [123-3] X test.pprint.HorizontalTests.Horizontal.collections.Buffer 6ms
[123-3] utest.AssertionError: expected.map(_.trim).contains(pprinted)
[123-3] expected: Seq[String] = ArraySeq(ArrayBuffer("omg", "wtf", "bbq"), WrappedArray("omg", "wtf", "bbq"))
[123-3] pprinted: String = ArrayDeque("omg", "wtf", "bbq")
[123-3] utest.asserts.Asserts$.assertImpl(Asserts.scala:30)
[123-3] test.pprint.Check.apply$$anonfun$1(Check.scala:22)
[123-3] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[123-3] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[123-3] scala.collection.immutable.List.foreach(List.scala:327)
[123-3] test.pprint.Check.apply(Check.scala:19)
[123-3] test.pprint.HorizontalTests$.$init$$$anonfun$1$$anonfun$1$$anonfun$3$$anonfun$7(HorizontalTests.scala:115) |
Keeping complexity guarantees in sync between platforms is more important than keeping better constant factors. If we're going to improve complexity guarantees in the JVM, we must also change the JS version. |
50b1a25 to
1e79afa
Compare
|
I have updated the Scala.js implementation as well which previously used The mima changes should go away once we tweak mima to allow standard library evolution |
As discussed in https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/66:
This PR adds the following convenience methods to
mutable.BufferThis PR basically swaps out
ArrayBufferin theBufferfactory objects withArrayDeque, and copies the uniqueArrayDequeconvenience methods over while forwarding them to the existing methods likeBuffer#remove. You could actually already do all these workflows withBufferalready, just that the API sucked (e.g.buffer.remove(buffer.length - 1)) and the asymptotic complexity of some operations sucked (e.g.buffer.remove(0)).This PR solves both those problems, so after this for most intents and purposes people reaching for the obvious thing
mutable.Buffer()will generally get everything they need without needing to separately reach formutable.ArrayDeque. There is still some im-precision in the types, since technically aBuffercould be aListBufferor some other weird data structure, but that's no worse than where we are today so it's still a strict improvementRegarding compatibility, we're only adding things to the API, which should be backwards binary and source compatible. And the change from
ArrayBuffertoArrayDequeonly improve the asymptotic complexity of some operations while leaving others unchangedI have updated the Scala.js implementation as well which previously used
js.WrappedArrayto also useArrayDeque