microsoft / hyperspace

An open source indexing subsystem that brings index-based query acceleration to Apache Spark™ and big data workloads.
https://aka.ms/hyperspace
Apache License 2.0
424 stars 115 forks source link

Content.rec(..) in LogEntry is recursive function, but does not use tail rec optimisation #400

Open dmytroDragan opened 3 years ago

dmytroDragan commented 3 years ago

Content.rec(..) in LogEntry is recursive function, but does not use tail rec optimisation

private def rec[T](
                      prefixPath: Path,
                      directory: Directory,
                      func: (FileInfo, Path) => T): Seq[T] = {
    val files = directory.files.map(f => func(f, prefixPath))
    files ++ directory.subDirs.flatMap { dir =>
      rec(new Path(prefixPath, dir.name), dir, func)
    }
  }

It is a potential issue which in some day could give StackOverflowError. I could quickly fix it.