Skip to content

Commit

Permalink
optimize a couple of lines in the function
Browse files Browse the repository at this point in the history
  • Loading branch information
vpranckaitis committed Jan 18, 2021
1 parent 421ca1b commit 4fcbf54
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/x/serialize/decoder_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TagValueFromEncodedTagsFast(
return nil, false, fmt.Errorf("missing size for tag name: index=%d", i)
}
numBytesName := int(byteOrder.Uint16(encodedTags[:2]))
if numBytesName <= 0 {
if numBytesName == 0 {
return nil, false, errEmptyTagNameLiteral
}
encodedTags = encodedTags[2:]
Expand All @@ -69,7 +69,7 @@ func TagValueFromEncodedTagsFast(
bytesValue := encodedTags[:numBytesValue]
encodedTags = encodedTags[numBytesValue:]

if bytes.Compare(bytesName, tagName) == 0 {
if bytes.Equal(bytesName, tagName) {
return bytesValue, true, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/x/serialize/decoder_fast_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var samples = []string{
"dScMAAgAX19uYW1lX18GAGRpc2tpbwQAYXJjaAMAeDY0CgBkYXRhY2VudGVyDwBhcC1ub3J0aGVhc3QtMWMIAGhvc3RuYW1lBwBob3N0XzM4CwBtZWFzdXJlbWVudAoAd3JpdGVfdGltZQIAb3MLAFVidW50dTE1LjEwBAByYWNrAgAyMAYAcmVnaW9uDgBhcC1ub3J0aGVhc3QtMQcAc2VydmljZQEAMBMAc2VydmljZV9lbnZpcm9ubWVudAcAc3RhZ2luZw8Ac2VydmljZV92ZXJzaW9uAQAwBAB0ZWFtAgBTRg==",
}

// BenchmarkTagValueFromEncodedTagsFast-12 8657110 140 ns/op
// BenchmarkTagValueFromEncodedTagsFast-12 11756650 110 ns/op
func BenchmarkTagValueFromEncodedTagsFast(b *testing.B) {
testData, err := prepareData(b)
require.NoError(b, err)
Expand Down

0 comments on commit 4fcbf54

Please sign in to comment.