Skip to content

Improve performance of buildableOfCollCond #373

@mdedetrich

Description

@mdedetrich

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions