Index: src/0dev.org/encoding/mtf/mtf.go ================================================================== --- src/0dev.org/encoding/mtf/mtf.go +++ src/0dev.org/encoding/mtf/mtf.go @@ -30,25 +30,18 @@ } // Encodes data in place func (c *context) encode(data []byte) { for index, value := range data { - - // Shortcut for sequential, equal values - if c.table[0] == value { - data[index] = 0 - continue - } - // Loop over the MTF table - for j := byte(1); j != 0; j++ { - if c.table[j] == value { + for i := byte(0); i <= 255; i++ { + if c.table[i] == value { // Output the value - data[index] = j + data[index] = i // Shift the table - copy(c.table[1:], c.table[:j]) + copy(c.table[1:], c.table[:i]) // Restore the value in front and break c.table[0] = value break } @@ -59,16 +52,10 @@ // Decode data in place func (c *context) decode(data []byte) { for index, value := range data { position := value - // Shortcut for sequential, equal values - if position == 0 { - data[index] = c.table[0] - continue - } - // Output the value data[index] = c.table[position] // Shift the table and restore the value in front copy(c.table[1:], c.table[:position])