Code review cleanup

This commit is contained in:
Erik Arvidsson
2015-08-05 13:37:28 -04:00
parent d834f7d546
commit c9d928f50b
2 changed files with 13 additions and 19 deletions

View File

@@ -172,14 +172,17 @@ func jsonDecodeCompoundBlob(input []interface{}, cs chunks.ChunkSource) (Future,
return nil, errInvalidEncoding
}
var err error
i := 0
length, err := toUint64(input[len(input)-1])
if err != nil {
return nil, err
}
numBlobs := len(input) / 2
offsets := make([]uint64, numBlobs)
blobs := make([]Future, numBlobs)
for i < len(input)-1 {
for i := 0; i < len(input)-1; i++ {
var err error
var offset uint64
if i == 0 {
offset = uint64(0)
@@ -192,18 +195,11 @@ func jsonDecodeCompoundBlob(input []interface{}, cs chunks.ChunkSource) (Future,
}
offsets[i/2] = offset
blobs[i/2], err = jsonDecodeValue(input[i], cs)
i++
if err != nil {
return nil, err
}
}
length, err := toUint64(input[i])
if err != nil {
return nil, err
}
Chk.Equal(len(input), i+1)
cb := compoundBlob{length, offsets, blobs, &ref.Ref{}, cs}
return futureFromValue(cb), nil
}

View File

@@ -166,22 +166,20 @@ func getChildJSON(f Future, s chunks.ChunkSink) (interface{}, error) {
func getJSONCompoundBlob(cb compoundBlob, s chunks.ChunkSink) (interface{}, error) {
// {"cb":[{"ref":"sha1-x"},length]}
// {"cb":[{"ref":"sha1-x"},offset,{"ref":"sha1-y"},length]}
var err error
l := make([]interface{}, len(cb.blobs)*2)
j := 0
l := make([]interface{}, 0, len(cb.blobs)*2)
for i, f := range cb.blobs {
if i != 0 {
l[j] = cb.offsets[i]
j++
l = append(l, cb.offsets[i])
}
if l[j], err = getChildJSON(f, s); err != nil {
c, err := getChildJSON(f, s)
if err != nil {
return nil, err
}
j++
l = append(l, c)
}
l[j] = cb.length
l = append(l, cb.length)
Chk.Equal(len(l), j+1)
Chk.Equal(len(l), len(cb.blobs)*2)
return map[string]interface{}{
"cb": l,