Skip to content

Commit

Permalink
*: tiny clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyesuifeng committed Dec 8, 2015
1 parent 25ba003 commit df410c9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions kv/index_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ type kvIndex struct {

// GenIndexPrefix generates the index prefix.
func GenIndexPrefix(indexPrefix string, indexID int64) (string, error) {
key, err := EncodeValue(indexID)
indexKey, err := EncodeValue(indexID)
if err != nil {
return "", errors.Trace(err)
}

return string(indexPrefix + string(key)), nil
return indexPrefix + string(indexKey), nil
}

// NewKVIndex builds a new kvIndex object.
Expand Down
3 changes: 0 additions & 3 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type Table interface {
// FindIndexByColName finds the index by column name.
FindIndexByColName(name string) *column.IndexedCol

// Prefix returns the table prefix string.
Prefix() string

// KeyPrefix returns the key prefix string.
KeyPrefix() string

Expand Down
17 changes: 5 additions & 12 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type Table struct {
publicColumns []*column.Col
writableColumns []*column.Col
indices []*column.IndexedCol
prefix []byte
recordPrefix string
encRecordPrefix []byte
indexPrefix string
Expand Down Expand Up @@ -109,7 +108,6 @@ func NewTable(tableID int64, tableName string, cols []*column.Col, alloc autoid.
t := &Table{
ID: tableID,
Name: name,
prefix: TablePrefix,
recordPrefix: fmt.Sprintf("%d_r", tableID),
indexPrefix: fmt.Sprintf("%d_i", tableID),
alloc: alloc,
Expand All @@ -122,13 +120,13 @@ func NewTable(tableID int64, tableName string, cols []*column.Col, alloc autoid.
if err != nil {
return t, errors.Trace(err)
}
t.encRecordPrefix = append(t.prefix, []byte(t.encRecordPrefix)...)
t.encRecordPrefix = append(TablePrefix, []byte(t.encRecordPrefix)...)

t.encIndexPrefix, err = kv.EncodeValue(t.indexPrefix)
if err != nil {
return t, errors.Trace(err)
}
t.encIndexPrefix = append(t.prefix, []byte(t.encIndexPrefix)...)
t.encIndexPrefix = append(TablePrefix, []byte(t.encIndexPrefix)...)

t.publicColumns = t.Cols()
t.writableColumns = t.writableCols()
Expand Down Expand Up @@ -264,11 +262,6 @@ func (t *Table) flatten(data interface{}) (interface{}, error) {
}
}

// Prefix implements table.Table Prefix interface.
func (t *Table) Prefix() string {
return string(t.prefix)
}

// KeyPrefix implements table.Table KeyPrefix interface.
func (t *Table) KeyPrefix() string {
return string(t.encRecordPrefix)
Expand All @@ -288,7 +281,7 @@ func (t *Table) RecordKey(h int64, col *column.Col) []byte {
key = EncodeRecordKey(t.recordPrefix, h, 0)
}

return append(t.prefix, key...)
return append(TablePrefix, key...)
}

// FirstKey implements table.Table FirstKey interface.
Expand Down Expand Up @@ -778,7 +771,7 @@ func EncodeRecordKey(tablePrefix string, h int64, columnID int64) []byte {
return buf
}

// DecodeRecordKey decodes the key and get the values.
// DecodeRecordKey decodes the key and gets the values.
func DecodeRecordKey(key []byte) ([]interface{}, error) {
if !bytes.HasPrefix(key, TablePrefix) {
return nil, errors.Errorf("invalid record key - %v", key)
Expand All @@ -793,7 +786,7 @@ func DecodeRecordKey(key []byte) ([]interface{}, error) {
return vals, nil
}

// DecodeRecordKeyHandle decodes the key and get the record handle.
// DecodeRecordKeyHandle decodes the key and gets the record handle.
func DecodeRecordKeyHandle(key string) (int64, error) {
vals, err := DecodeRecordKey([]byte(key))
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions util/codec/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ func DecodeBytes(b []byte) ([]byte, []byte, error) {
}

// EncodeBytesDesc first encodes bytes using EncodeBytes, then bitwise reverses
// encoded value to guarentee the encoded value is in descending order for comparison,
// The encoded value is >= SmallestNoneNilValue and < InfiniteValue.
// encoded value to guarentee the encoded value is in descending order for comparison。
func EncodeBytesDesc(b []byte, data []byte) []byte {
n := len(b)
b = EncodeBytes(b, data)
Expand Down
4 changes: 2 additions & 2 deletions util/codec/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func codecValue(value []byte, valSign int64) {
// Decimal encoding:
// Byte -> value sign
// Byte -> exp sign
// Byte -> exp value
// EncodeInt -> exp value
// EncodeBytes -> abs value bytes
func EncodeDecimal(b []byte, d mysql.Decimal) []byte {
if d.Equals(mysql.ZeroDecimal) {
Expand Down Expand Up @@ -122,7 +122,7 @@ func EncodeDecimal(b []byte, d mysql.Decimal) []byte {
// Decimal decoding:
// Byte -> value sign
// Byte -> exp sign
// Byte -> exp value
// DecodeInt -> exp value
// DecodeBytes -> abs value bytes
func DecodeDecimal(b []byte) ([]byte, mysql.Decimal, error) {
var (
Expand Down

0 comments on commit df410c9

Please sign in to comment.