File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ type Format struct {
27
27
// for each reference. fieldDelim and refDelim should be selected to not
28
28
// interfere with each other and to not be present in field values.
29
29
fieldDelim []byte
30
+ // fieldDelimStr is a string representation of fieldDelim. Used to save
31
+ // us from repetitive reallocation whenever we need the delimiter as a
32
+ // string.
33
+ fieldDelimStr string
30
34
// refDelim is the character sequence used to separate reference from
31
35
// each other in the output. fieldDelim and refDelim should be selected
32
36
// to not interfere with each other and to not be present in field
@@ -38,9 +42,10 @@ type Format struct {
38
42
// git-for-each-ref(1) for available fields.
39
43
func NewFormat (fieldNames ... string ) Format {
40
44
return Format {
41
- fieldNames : fieldNames ,
42
- fieldDelim : nullChar ,
43
- refDelim : dualNullChar ,
45
+ fieldNames : fieldNames ,
46
+ fieldDelim : nullChar ,
47
+ fieldDelimStr : string (nullChar ),
48
+ refDelim : dualNullChar ,
44
49
}
45
50
}
46
51
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ func NewParser(r io.Reader, format Format) *Parser {
35
35
scanner .Split (
36
36
func (data []byte , atEOF bool ) (advance int , token []byte , err error ) {
37
37
// Scan until delimiter, marking end of reference.
38
- delimIdx := bytes .Index (data , [] byte ( format .refDelim ) )
38
+ delimIdx := bytes .Index (data , format .refDelim )
39
39
if delimIdx >= 0 {
40
40
token := data [:delimIdx ]
41
41
advance := delimIdx + len (format .refDelim )
@@ -93,7 +93,7 @@ func (p *Parser) parseRef(refBlock string) (map[string]string, error) {
93
93
94
94
fieldValues := make (map [string ]string )
95
95
96
- fields := strings .Split (refBlock , string ( p .format .fieldDelim ) )
96
+ fields := strings .Split (refBlock , p .format .fieldDelimStr )
97
97
if len (fields ) != len (p .format .fieldNames ) {
98
98
return nil , fmt .Errorf ("unexpected number of reference fields: wanted %d, was %d" ,
99
99
len (fields ), len (p .format .fieldNames ))
You can’t perform that action at this time.
0 commit comments