Gotos to simplify uses of the new encoder pools.

For maintainability.
pull/7371/head
rw 2016-09-27 11:47:25 -07:00
parent 1eda0277a7
commit 9429a2f96a
1 changed files with 44 additions and 44 deletions

View File

@ -230,7 +230,7 @@ func (f *FloatValue) String() string {
return fmt.Sprintf("%v %v", time.Unix(0, f.unixnano), f.value)
}
func encodeFloatBlock(buf []byte, values []Value) ([]byte, error) {
func encodeFloatBlock(buf []byte, values []Value) (b []byte, err error) {
if len(values) == 0 {
return nil, nil
}
@ -251,27 +251,27 @@ func encodeFloatBlock(buf []byte, values []Value) ([]byte, error) {
}
venc.Finish()
var tb, vb []byte
// Encoded timestamp values
tb, err := tsenc.Bytes()
tb, err = tsenc.Bytes()
if err != nil {
putTimeEncoder(tsenc)
putFloatEncoder(venc)
return nil, err
goto cleanup
}
// Encoded float values
vb, err := venc.Bytes()
vb, err = venc.Bytes()
if err != nil {
putTimeEncoder(tsenc)
putFloatEncoder(venc)
return nil, err
goto cleanup
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
b := packBlock(buf, BlockFloat64, tb, vb)
b = packBlock(buf, BlockFloat64, tb, vb)
cleanup:
putTimeEncoder(tsenc)
putFloatEncoder(venc)
return b, nil
return
}
@ -342,7 +342,7 @@ func (f *BooleanValue) String() string {
return fmt.Sprintf("%v %v", time.Unix(0, f.unixnano), f.Value())
}
func encodeBooleanBlock(buf []byte, values []Value) ([]byte, error) {
func encodeBooleanBlock(buf []byte, values []Value) (b []byte, err error) {
if len(values) == 0 {
return nil, nil
}
@ -359,27 +359,27 @@ func encodeBooleanBlock(buf []byte, values []Value) ([]byte, error) {
venc.Write(v.(*BooleanValue).value)
}
var tb, vb []byte
// Encoded timestamp values
tb, err := tsenc.Bytes()
tb, err = tsenc.Bytes()
if err != nil {
putTimeEncoder(tsenc)
putBooleanEncoder(venc)
return nil, err
goto cleanup
}
// Encoded float values
vb, err := venc.Bytes()
vb, err = venc.Bytes()
if err != nil {
putTimeEncoder(tsenc)
putBooleanEncoder(venc)
return nil, err
goto cleanup
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
b := packBlock(buf, BlockBoolean, tb, vb)
b = packBlock(buf, BlockBoolean, tb, vb)
cleanup:
putTimeEncoder(tsenc)
putBooleanEncoder(venc)
return b, nil
return
}
func DecodeBooleanBlock(block []byte, tdec *TimeDecoder, vdec *BooleanDecoder, a *[]BooleanValue) ([]BooleanValue, error) {
@ -447,7 +447,7 @@ func (f *IntegerValue) String() string {
return fmt.Sprintf("%v %v", time.Unix(0, f.unixnano), f.Value())
}
func encodeIntegerBlock(buf []byte, values []Value) ([]byte, error) {
func encodeIntegerBlock(buf []byte, values []Value) (b []byte, err error) {
tsEnc := getTimeEncoder(len(values))
vEnc := getIntegerEncoder(len(values))
@ -456,26 +456,26 @@ func encodeIntegerBlock(buf []byte, values []Value) ([]byte, error) {
vEnc.Write(v.(*IntegerValue).value)
}
var tb, vb []byte
// Encoded timestamp values
tb, err := tsEnc.Bytes()
tb, err = tsEnc.Bytes()
if err != nil {
putTimeEncoder(tsEnc)
putIntegerEncoder(vEnc)
return nil, err
goto cleanup
}
// Encoded int64 values
vb, err := vEnc.Bytes()
vb, err = vEnc.Bytes()
if err != nil {
putTimeEncoder(tsEnc)
putIntegerEncoder(vEnc)
return nil, err
goto cleanup
}
// Prepend the first timestamp of the block in the first 8 bytes
b := packBlock(buf, BlockInteger, tb, vb)
b = packBlock(buf, BlockInteger, tb, vb)
cleanup:
putTimeEncoder(tsEnc)
putIntegerEncoder(vEnc)
return b, nil
return
}
func DecodeIntegerBlock(block []byte, tdec *TimeDecoder, vdec *IntegerDecoder, a *[]IntegerValue) ([]IntegerValue, error) {
@ -544,7 +544,7 @@ func (f *StringValue) String() string {
return fmt.Sprintf("%v %v", time.Unix(0, f.unixnano), f.Value())
}
func encodeStringBlock(buf []byte, values []Value) ([]byte, error) {
func encodeStringBlock(buf []byte, values []Value) (b []byte, err error) {
tsEnc := getTimeEncoder(len(values))
vEnc := getStringEncoder(len(values) * len(values[0].(*StringValue).value))
@ -553,26 +553,26 @@ func encodeStringBlock(buf []byte, values []Value) ([]byte, error) {
vEnc.Write(v.(*StringValue).value)
}
var tb, vb []byte
// Encoded timestamp values
tb, err := tsEnc.Bytes()
tb, err = tsEnc.Bytes()
if err != nil {
putTimeEncoder(tsEnc)
putStringEncoder(vEnc)
return nil, err
goto cleanup
}
// Encoded string values
vb, err := vEnc.Bytes()
vb, err = vEnc.Bytes()
if err != nil {
putTimeEncoder(tsEnc)
putStringEncoder(vEnc)
return nil, err
goto cleanup
}
// Prepend the first timestamp of the block in the first 8 bytes
b := packBlock(buf, BlockString, tb, vb)
b = packBlock(buf, BlockString, tb, vb)
cleanup:
putTimeEncoder(tsEnc)
putStringEncoder(vEnc)
return b, nil
return
}
func DecodeStringBlock(block []byte, tdec *TimeDecoder, vdec *StringDecoder, a *[]StringValue) ([]StringValue, error) {