diff options
author | Antonio Navarro Perez <antnavper@gmail.com> | 2016-12-14 13:46:43 +0100 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2016-12-14 13:46:43 +0100 |
commit | df0f38af83f972f026d7e14150f3d37b95f13484 (patch) | |
tree | bd9156ebf016ed4a429da72c096a5f885b93d12d /plumbing | |
parent | 500b1e1e183c73e3087710fca2f96acfd2e2d5cb (diff) | |
download | go-git-df0f38af83f972f026d7e14150f3d37b95f13484.tar.gz |
packfile: improve delta copy operation encoding code (#186)
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/packfile/diff_delta.go | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go index 7a32d5d..fb05a79 100644 --- a/plumbing/format/packfile/diff_delta.go +++ b/plumbing/format/packfile/diff_delta.go @@ -134,39 +134,21 @@ func encodeCopyOperation(offset, length int) []byte { code := 0x80 var opcodes []byte - if offset&0xff != 0 { - opcodes = append(opcodes, byte(offset&0xff)) - code |= 0x01 - } - - if offset&0xff00 != 0 { - opcodes = append(opcodes, byte((offset&0xff00)>>8)) - code |= 0x02 - } - - if offset&0xff0000 != 0 { - opcodes = append(opcodes, byte((offset&0xff0000)>>16)) - code |= 0x04 - } - - if offset&0xff000000 != 0 { - opcodes = append(opcodes, byte((offset&0xff000000)>>24)) - code |= 0x08 - } - - if length&0xff != 0 { - opcodes = append(opcodes, byte(length&0xff)) - code |= 0x10 - } - - if length&0xff00 != 0 { - opcodes = append(opcodes, byte((length&0xff00)>>8)) - code |= 0x20 + var i uint + for i = 0; i < 4; i++ { + f := 0xff << (i * 8) + if offset&f != 0 { + opcodes = append(opcodes, byte(offset&f>>(i*8))) + code |= 0x01 << i + } } - if length&0xff0000 != 0 { - opcodes = append(opcodes, byte((length&0xff0000)>>16)) - code |= 0x40 + for i = 0; i < 3; i++ { + f := 0xff << (i * 8) + if length&f != 0 { + opcodes = append(opcodes, byte(length&f>>(i*8))) + code |= 0x10 << i + } } return append([]byte{byte(code)}, opcodes...) |