Skip to content

Commit

Permalink
add defaultLimit and use it when resetting back (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-vasile authored May 22, 2024
1 parent 341c422 commit bc511b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion mimetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"sync/atomic"
)

var defaultLimit uint32 = 3072

// readLimit is the maximum number of bytes from the input used when detecting.
var readLimit uint32 = 3072
var readLimit uint32 = defaultLimit

// Detect returns the MIME type found from the provided byte slice.
//
Expand Down
9 changes: 4 additions & 5 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestConcurrent(t *testing.T) {

wg.Wait()
// Reset to original limit for benchmarks.
SetLimit(3072)
SetLimit(defaultLimit)
}

// For #162.
Expand All @@ -469,7 +469,7 @@ func TestEmptyInput(t *testing.T) {
if !mtype.Is(plain) {
t.Fatalf("0 limit, empty reader detection; expected: %s, got: %s", plain, mtype)
}
SetLimit(3072)
SetLimit(defaultLimit)
}

// Benchmarking a random slice of bytes is as close as possible to the real
Expand All @@ -480,7 +480,7 @@ func TestEmptyInput(t *testing.T) {
// might be tested for zip, gzip, etc., before it is identified.
func BenchmarkSliceRand(b *testing.B) {
r := rand.New(rand.NewSource(0))
data := make([]byte, 3072)
data := make([]byte, defaultLimit)
if _, err := io.ReadFull(r, data); err != io.ErrUnexpectedEOF && err != nil {
b.Fatal(err)
}
Expand All @@ -497,7 +497,7 @@ func BenchmarkSliceRand(b *testing.B) {

func BenchmarkAll(b *testing.B) {
r := rand.New(rand.NewSource(0))
data := make([]byte, 3072)
data := make([]byte, defaultLimit)
if _, err := io.ReadFull(r, data); err != io.ErrUnexpectedEOF && err != nil {
b.Fatal(err)
}
Expand All @@ -510,7 +510,6 @@ func BenchmarkAll(b *testing.B) {
}
})
}

}

func BenchmarkCommon(b *testing.B) {
Expand Down

0 comments on commit bc511b8

Please sign in to comment.