Check-in [3ea011cf07]
Overview
SHA1:3ea011cf07938f5ec605e43ea957f6135dd47e57
Date: 2015-01-14 20:46:02
User: spaskalev
Comment:Use for range in mtf's encoder for the position table.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-01-26
20:30
[61b0c5b57a] Added tbd from gophergala/tbd :) (user: spaskalev, tags: trunk)
2015-01-14
20:46
[3ea011cf07] Use for range in mtf's encoder for the position table. (user: spaskalev, tags: trunk)
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)
Changes

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

    27     27   
    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         -	for index, value := range data {
           34  +	for dataIndex, dataValue := range data {
    35     35   		// Loop over the MTF table
    36         -		for i := byte(0); i <= 255; i++ {
    37         -			if c.table[i] == value {
           36  +		for tableIndex, tableValue := range c.table {
           37  +			if tableValue == dataValue {
    38     38   				// Output the value
    39         -				data[index] = i
           39  +				data[dataIndex] = byte(tableIndex)
    40     40   
    41     41   				// Shift the table
    42         -				copy(c.table[1:], c.table[:i])
           42  +				copy(c.table[1:], c.table[:tableIndex])
    43     43   
    44     44   				// Restore the value in front and break
    45         -				c.table[0] = value
           45  +				c.table[0] = dataValue
    46     46   				break
    47     47   			}
    48     48   		}
    49     49   	}
    50     50   }
    51     51   
    52     52   // Decode data in place

Modified src/0dev.org/encoding/mtf/mtf_test.go from [74a3c46eb8] to [7051812004].

    20     20   
    21     21   	io.Copy(&output, decoder)
    22     22   	processed := output.Bytes()
    23     23   
    24     24   	delta := diff.Diff(diff.D{Len1: len(data), Len2: len(processed),
    25     25   		EqualFunc: func(i, j int) bool { return data[i] == processed[j] }})
    26     26   	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
    27         -		t.Error("Differences detected ", delta)
           27  +		t.Error("Differences detected ", delta, processed)
    28     28   	}
    29     29   }