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

patch a perf bottleneck #79

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion io/src/main/scala/sbt/io/Hash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package sbt.io

import java.io.{ ByteArrayInputStream, File, InputStream }
import java.net.{ URI, URL }
import java.nio.file.Files

object Hash {
private val BufferSize = 8192
Expand Down Expand Up @@ -52,7 +53,7 @@ object Hash {
def apply(as: Array[Byte]): Array[Byte] = apply(new ByteArrayInputStream(as))

/** Calculates the SHA-1 hash of the given file.*/
def apply(file: File): Array[Byte] = Using.fileInputStream(file)(apply)
def apply(file: File): Array[Byte] = Files.readAllBytes(file.toPath)
Copy link
Member

Choose a reason for hiding this comment

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

Wat. This reads all the bytes in the file. It doesn't calculate the SHA-1 hash for it..

Copy link
Author

Choose a reason for hiding this comment

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

well then apply the hash to it afterwards... the slow bit is the FileFilterStream

like I said, I have absolutely no way of validating anything about this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ok.

Copy link
Author

Choose a reason for hiding this comment

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

  def apply(file: File): Array[Byte] = apply(Files.readAllBytes(file.toPath))


/** Calculates the SHA-1 hash of the given resource.*/
def apply(url: URL): Array[Byte] = Using.urlInputStream(url)(apply)
Expand Down