Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 825c00d

Browse files
ajnavarrosmola
authored andcommitted
packfile: improve delta copy operation encoding code (#186)
1 parent 1d78a9a commit 825c00d

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

plumbing/format/packfile/diff_delta.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -134,39 +134,21 @@ func encodeCopyOperation(offset, length int) []byte {
134134
code := 0x80
135135
var opcodes []byte
136136

137-
if offset&0xff != 0 {
138-
opcodes = append(opcodes, byte(offset&0xff))
139-
code |= 0x01
140-
}
141-
142-
if offset&0xff00 != 0 {
143-
opcodes = append(opcodes, byte((offset&0xff00)>>8))
144-
code |= 0x02
145-
}
146-
147-
if offset&0xff0000 != 0 {
148-
opcodes = append(opcodes, byte((offset&0xff0000)>>16))
149-
code |= 0x04
150-
}
151-
152-
if offset&0xff000000 != 0 {
153-
opcodes = append(opcodes, byte((offset&0xff000000)>>24))
154-
code |= 0x08
155-
}
156-
157-
if length&0xff != 0 {
158-
opcodes = append(opcodes, byte(length&0xff))
159-
code |= 0x10
160-
}
161-
162-
if length&0xff00 != 0 {
163-
opcodes = append(opcodes, byte((length&0xff00)>>8))
164-
code |= 0x20
137+
var i uint
138+
for i = 0; i < 4; i++ {
139+
f := 0xff << (i * 8)
140+
if offset&f != 0 {
141+
opcodes = append(opcodes, byte(offset&f>>(i*8)))
142+
code |= 0x01 << i
143+
}
165144
}
166145

167-
if length&0xff0000 != 0 {
168-
opcodes = append(opcodes, byte((length&0xff0000)>>16))
169-
code |= 0x40
146+
for i = 0; i < 3; i++ {
147+
f := 0xff << (i * 8)
148+
if length&f != 0 {
149+
opcodes = append(opcodes, byte(length&f>>(i*8)))
150+
code |= 0x10 << i
151+
}
170152
}
171153

172154
return append([]byte{byte(code)}, opcodes...)

0 commit comments

Comments
 (0)