Check-in [5c9c0a2164]
Overview
SHA1:5c9c0a2164ec08b6bb7d2f5fa5ca42dc45a6588a
Date: 2015-01-10 21:28:17
User: spaskalev
Comment:encoding/mtf optimizations
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-01-11
08:44
[90877fa64f] Switched encoding/fibonacci.Encoder back to using a 2-bytes array as a preallocated write buffer. It seems that it otherwise escapes everytime and calls a causes a lot of allocations and subsequent gc work. (user: spaskalev, tags: trunk)
2015-01-10
21:28
[5c9c0a2164] encoding/mtf optimizations (user: spaskalev, tags: trunk)
2015-01-04
16:45
[9ded78a659] Use a lookup table for fibonacci's encoding of bytes. (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/encoding/mtf/mtf.go from [cebf1719c8] to [76460f96cb].

    28     28   type context struct {
    29     29   	table [256]byte
    30     30   }
    31     31   
    32     32   // Encodes data in place
    33     33   func (c *context) encode(data []byte) {
    34     34   	for index, value := range data {
    35         -
    36         -		// Shortcut for sequential, equal values
    37         -		if c.table[0] == value {
    38         -			data[index] = 0
    39         -			continue
    40         -		}
    41         -
    42     35   		// Loop over the MTF table
    43         -		for j := byte(1); j != 0; j++ {
    44         -			if c.table[j] == value {
           36  +		for i := byte(0); i <= 255; i++ {
           37  +			if c.table[i] == value {
    45     38   				// Output the value
    46         -				data[index] = j
           39  +				data[index] = i
    47     40   
    48     41   				// Shift the table
    49         -				copy(c.table[1:], c.table[:j])
           42  +				copy(c.table[1:], c.table[:i])
    50     43   
    51     44   				// Restore the value in front and break
    52     45   				c.table[0] = value
    53     46   				break
    54     47   			}
    55     48   		}
    56     49   	}
................................................................................
    57     50   }
    58     51   
    59     52   // Decode data in place
    60     53   func (c *context) decode(data []byte) {
    61     54   	for index, value := range data {
    62     55   		position := value
    63     56   
    64         -		// Shortcut for sequential, equal values
    65         -		if position == 0 {
    66         -			data[index] = c.table[0]
    67         -			continue
    68         -		}
    69         -
    70     57   		// Output the value
    71     58   		data[index] = c.table[position]
    72     59   
    73     60   		// Shift the table and restore the value in front
    74     61   		copy(c.table[1:], c.table[:position])
    75     62   		c.table[0] = data[index]
    76     63   	}