This repository was archived by the owner on Apr 12, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +5
-24
lines changed Expand file tree Collapse file tree 1 file changed +5
-24
lines changed Original file line number Diff line number Diff line change 5
5
package git
6
6
7
7
import (
8
+ "bytes"
8
9
"encoding/hex"
9
10
"fmt"
10
11
"strings"
@@ -26,43 +27,23 @@ func (id SHA1) Equal(s2 interface{}) bool {
26
27
}
27
28
return v == id .String ()
28
29
case []byte :
29
- if len (v ) != 20 {
30
- return false
31
- }
32
- for i , v := range v {
33
- if id [i ] != v {
34
- return false
35
- }
36
- }
30
+ return bytes .Equal (v , id [:])
37
31
case SHA1 :
38
- for i , v := range v {
39
- if id [i ] != v {
40
- return false
41
- }
42
- }
32
+ return v == id
43
33
default :
44
34
return false
45
35
}
46
- return true
47
36
}
48
37
49
38
// String returns string (hex) representation of the Oid.
50
39
func (id SHA1 ) String () string {
51
- result := make ([]byte , 0 , 40 )
52
- hexvalues := []byte ("0123456789abcdef" )
53
- for i := 0 ; i < 20 ; i ++ {
54
- result = append (result , hexvalues [id [i ]>> 4 ])
55
- result = append (result , hexvalues [id [i ]& 0xf ])
56
- }
57
- return string (result )
40
+ return hex .EncodeToString (id [:])
58
41
}
59
42
60
43
// MustID always creates a new SHA1 from a [20]byte array with no validation of input.
61
44
func MustID (b []byte ) SHA1 {
62
45
var id SHA1
63
- for i := 0 ; i < 20 ; i ++ {
64
- id [i ] = b [i ]
65
- }
46
+ copy (id [:], b )
66
47
return id
67
48
}
68
49
You can’t perform that action at this time.
0 commit comments