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

Improve performance of buildableOfCollCond #373

Open
mdedetrich opened this issue Feb 16, 2023 · 0 comments
Open

Improve performance of buildableOfCollCond #373

mdedetrich opened this issue Feb 16, 2023 · 0 comments

Comments

@mdedetrich
Copy link
Collaborator

Current implementation of buildableOfCollCond isn't as performant as it could be, an alternative version such as

@SuppressWarnings(
  Array(
    "scalafix:DisableSyntax.while",
    "scalafix:DisableSyntax.return"
  )
)
@scala.annotation.nowarn("msg=return statement uses an exception")
private def buildableOfCollCond[C <: Iterable[T], T](cond: C => Boolean, g: Gen[C])(implicit
    evb: Buildable[T, C]
): Gen[C] =
  Gen.infiniteLazyList(g).map { ll =>
    val it   = ll.iterator
    val bldr = evb.builder
    while (true) {
      val result = bldr.result()
      if (cond(result)) {
        return result
      }
      bldr ++= it.next()
    }
    return bldr.result()
  }

Note that this version of buildableOfCollCond doesn't actually it (it seems to have termination issues).

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

No branches or pull requests

1 participant