From ed57d0e51fa21b7b046e2cd84096caa86be1636c Mon Sep 17 00:00:00 2001 From: rochala Date: Wed, 11 Sep 2024 18:47:04 +0200 Subject: [PATCH] Copy bytes directly instead of using scala.reflect.io.Streamable suboptimal methods --- .../src/main/scala/xsbt/AbstractZincFile.scala | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/compiler-bridge/src/main/scala/xsbt/AbstractZincFile.scala b/internal/compiler-bridge/src/main/scala/xsbt/AbstractZincFile.scala index 2398339a2..b3352a8fd 100644 --- a/internal/compiler-bridge/src/main/scala/xsbt/AbstractZincFile.scala +++ b/internal/compiler-bridge/src/main/scala/xsbt/AbstractZincFile.scala @@ -12,7 +12,6 @@ package xsbt import xsbti.{ PathBasedFile, VirtualFile } -import scala.reflect.io.Streamable private trait AbstractZincFile extends scala.reflect.io.AbstractFile { def underlying: VirtualFile @@ -25,7 +24,22 @@ private final class ZincPlainFile private[xsbt] (val underlying: PathBasedFile) private final class ZincVirtualFile private[xsbt] (val underlying: VirtualFile) extends scala.reflect.io.VirtualFile(underlying.name, underlying.id) with AbstractZincFile { - Streamable.closing(output)(_.write(Streamable.bytes(underlying.input))) // fill in the content + val buffer = new Array[Byte](4096) + + val in = underlying.input() + val output0 = output + + try { + var readBytes = in.read(buffer) + + while (readBytes != -1) { + output0.write(buffer, 0, readBytes) + readBytes = in.read(buffer) + } + } finally { + in.close() + output0.close() + } } private object AbstractZincFile {