Skip to content
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

Port/implement j.u.ArrayDeque #1696

Merged
merged 4 commits into from May 22, 2020
Merged

Conversation

LeeTibbert
Copy link
Contributor

Documentation:

  • The standard changelog entry is requested.

Testing:

  • Built and tested ("test-all") in release-fast mode using sbt 1.2.8 on
    X86_64 only . All tests pass.

LeeTibbert pushed a commit to LeeTibbert/scala-native-fork that referenced this pull request Aug 28, 2019
Use ArrayDeque from recent SN PR scala-native#1696 to match the changes in the re2j
PR.  Eliminating SN divergence should make it easier to merge some
known re2j changes planned for two or more rounds out.
@LeeTibbert
Copy link
Contributor Author

preemptively rebased. Travis CI is all green.

Copy link
Collaborator

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Thanks. I have a few minor comments.

/// * The order of method declarations is not alphabetical to reduce
/// churn versus ScalaJs original.

class ArrayDeque[E] private (private var inner: ArrayList[E])
Copy link
Collaborator

Choose a reason for hiding this comment

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

inner is never reassigned. It could and should be a val.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Good catch.


def pollLast(): E = {
if (inner.isEmpty) null.asInstanceOf[E]
else inner.remove(inner.size - 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The else branch should also increase the status, like in pollFirst().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. oops!


private def failFastIterator(startIndex: Int, nex: (Int) => Int) = {
new Iterator[E] {
private def checkStatus() =
Copy link
Collaborator

Choose a reason for hiding this comment

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

A method body spanning several lines should be enclosed in {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, artifact of original code.

// ArrayList.spliterator is not yet implemented.
// def spliterator(): Spliterator[E] = inner.spliterator()
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, since spliterators are not implemented anywhere, I recommended not even mentioning it here, even commented. If we one day add spliterators, we'll have to implement them everywhere anyway, in a holistic fashion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// def spliterator(): Spliterator[E] = inner.spliterator()

override def toArray(): Array[AnyRef] = {
inner.toArray(new Array[AnyRef](size))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
inner.toArray(new Array[AnyRef](size))
inner.toArray()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. The replacement is more focused and concise. Thank you.

*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove that header and just have a comment // Ported from Scala.js, like all the other files that have been ported from Scala.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

/// * equals() & hashcode() are not implemented so comparing ArrayDeque
/// instances ad1 == ad2 is bit of a pain. It gives object equality
/// not the more useful contents equality. Someday...
/// https://alvinalexander.com/scala/ \
/// how-to-define-equals-hashcode-methods-in-scala-object-equality
Copy link
Collaborator

Choose a reason for hiding this comment

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

equals and hashCode are inherited from AbstractList, which has a correct implementation. This comment is misleading and should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thank you for the insight & correction.

/// * spliterator() is implemented but commented out because the
/// ArrayList.spliterator it delegates to is not yet implemented.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed together with the commented out definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

  * This PR ports java.util.ArrayDeque from Scala.js and extensively
    modifies it for ScalaNative.

    My thanks and appreciation to @sjrd and the Scala.js team for
    the original code.  As a token of that appreciation, I hope to
    backfile a PR for a slight deviation in Scala.js from JVM
    behavior in AbstractCollection.toString.

    All bugs introduced and misbehaviors are my original contribution.

  * The test suite ArrayDequeSuite.scala was created.

    One test is marked `testFails`. See SN Issue scala-native#1694
    "j.l.System.arraycopy should more closely match JVM; missing
    ArrayStoreExceptions" for details. It is not evident how
    the failing test relates to Issue scala-native#1694, but it a week or so
    of tracing will show that it does.

Documentation:

  * The standard changelog entry is requested.

Testing:

  * Built and tested ("test-all") in release-fast mode using sbt 1.2.8 on
    X86_64 only . All tests pass.
@LeeTibbert
Copy link
Contributor Author

FYI: I documented at the top of ArrayDeque.scala that the change in Scala.js to the file
that was ported did not need to be made in this file. The test Suite of this PR already had
tests which should shore up that assertion.

Copy link
Collaborator

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Looks good, except for the comment below.

javalib/src/main/scala/java/util/ArrayDeque.scala Outdated Show resolved Hide resolved
Copy link
Collaborator

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Thank you!

@sjrd sjrd merged commit 9bfd3fa into scala-native:master May 22, 2020
LeeTibbert pushed a commit to LeeTibbert/scala-native-fork that referenced this pull request May 22, 2020
Use ArrayDeque from recent SN PR scala-native#1696 to match the changes in the re2j
PR.  Eliminating SN divergence should make it easier to merge some
known re2j changes planned for two or more rounds out.
ekrich pushed a commit to ekrich/scala-native that referenced this pull request May 21, 2021
This commit ports java.util.ArrayDeque from Scala.js and extensively
modifies it for ScalaNative.

One test is marked `testFails`. See SN Issue scala-native#1694
"j.l.System.arraycopy should more closely match JVM; missing
ArrayStoreExceptions" for details.
jchyb pushed a commit to jchyb/scala-native that referenced this pull request Oct 4, 2021
Use ArrayDeque from recent SN PR scala-native#1696 to match the changes in the re2j
PR.  Eliminating SN divergence should make it easier to merge some
known re2j changes planned for two or more rounds out.
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.

None yet

2 participants