Browse Source

changes based on gofmt -s; fixed small performance issue with NoChecksum==true

Pierre Curto 10 years ago
parent
commit
5dc165e8dd
2 changed files with 19 additions and 17 deletions
  1. 16 16
      lz4_test.go
  2. 3 1
      reader.go

+ 16 - 16
lz4_test.go

@@ -86,20 +86,20 @@ var (
 	lorem = []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
 	// Initial data items used for testing. More are added with random and other kind of data.
 	testDataItems = []testData{
-		testData{"empty", nil},
-		testData{
+		{"empty", nil},
+		{
 			"small pattern",
 			[]byte("aaaaaaaaaaaaaaaaaaa"),
 		},
-		testData{
+		{
 			"small pattern long",
 			[]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
 		},
-		testData{
+		{
 			"medium pattern",
 			[]byte("abcdefghijklmnopqabcdefghijklmnopq"),
 		},
-		testData{
+		{
 			"lorem",
 			lorem,
 		},
@@ -174,13 +174,13 @@ func buildHeaders(options map[string][]interface{}) []testHeader {
 func init() {
 	// Only set the relevant headers having an impact on the comrpession.
 	seed := map[string][]interface{}{
-		"BlockDependency": []interface{}{true},
-		"BlockChecksum":   []interface{}{true},
-		"NoChecksum":      []interface{}{true},
-		// "Dict":            []interface{}{true},
+		"BlockDependency": {true},
+		"BlockChecksum":   {true},
+		"NoChecksum":      {true},
+		// "Dict":            {true},
 		// Enabling this substantially increase the testing time.
 		// As this test is not really required it is disabled.
-		// "HighCompression": []interface{}{true},
+		// "HighCompression": {true},
 	}
 	for _, bms := range lz4.BlockMaxSizeItems {
 		seed["BlockMaxSize"] = append(seed["BlockMaxSize"], bms)
@@ -307,14 +307,14 @@ func BenchmarkCompressBlockHC(b *testing.B) {
 func TestNoWrite(t *testing.T) {
 	// that is 2*2*2*2*2*2^4 = 512 headers!
 	seed := map[string][]interface{}{
-		"BlockDependency": []interface{}{true},
-		"BlockChecksum":   []interface{}{true},
-		"NoChecksum":      []interface{}{true},
-		"Size":            []interface{}{999},
-		// "Dict":            []interface{}{true},
+		"BlockDependency": {true},
+		"BlockChecksum":   {true},
+		"NoChecksum":      {true},
+		"Size":            {999},
+		// "Dict":            {true},
 		// Enabling this substantially increase the testing time.
 		// As this test is not really required it is disabled.
-		// "HighCompression": []interface{}{true},
+		// "HighCompression": {true},
 	}
 	for _, bms := range lz4.BlockMaxSizeItems {
 		seed["BlockMaxSize"] = append(seed["BlockMaxSize"], bms)

+ 3 - 1
reader.go

@@ -205,7 +205,9 @@ func (z *Reader) Read(buf []byte) (n int, err error) {
 			return n, zb.err
 		}
 		bLen := len(zb.data)
-		z.checksum.Write(zb.data)
+		if !z.NoChecksum {
+			z.checksum.Write(zb.data)
+		}
 		m := copy(buf[n:], zb.data)
 		// buffer the remaining data (this is necessarily the last block)
 		if m < bLen {