Check-in [98661a7373]
Overview
SHA1:98661a7373a227c7d052e5303913980c36740da7
Date: 2015-01-02 14:35:48
User: spaskalev
Comment:Minor optimizations to fibonacci.Encoder
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-01-02
17:55
[783d0b7f51] update the copyright notice for 2015 (user: spaskalev, tags: trunk)
14:35
[98661a7373] Minor optimizations to fibonacci.Encoder (user: spaskalev, tags: trunk)
2015-01-01
15:19
[cb736e7ad3] [fibonacci] renamed Writer->Encoder, Reader->Decoder. [mtf] moved package mtf to encoding\mtf (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/encoding/fibonacci/fib.go from [3231551b1f] to [4b4dfe919b].

128
129
130
131
132
133
134

135
136
137







138
139
140
141
142
143
144
145
...
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203


204
205
206
207
208
209
210

			continue
		}

		// Clearing e.length is not necessary as it will be overwritten later

		// Stage the complete byte for writing

		buffer := []byte{byte(e.remaining)}

		// Stage every full byte from the encoded value for writing







		for enc > 128 {
			buffer = append(buffer, byte(enc))
			enc >>= 8
			len -= 8
		}

		// Store the remaining bits
		e.remaining, e.length = byte(enc), len
................................................................................
		output[0] = byte(val)

		// Advance the internal and output buffers
		output = output[1:]
		d.buffer >>= len
		d.at -= len


		total++
	}

	// Termination condition
	if len(output) == 0 || err != nil {
		return total, err
	}

	// We need to limit the output's size else we could end up with a lot of small values
	// that fit neither in the output slice nor in the internal buffer


	free := int((63 ^ d.at) >> 3)
	if free > len(output) {
		free = len(output)
	}

	// Read data and transfer to the internal buffer
	count, err := d.source.Read(output[:free])







>
|


>
>
>
>
>
>
>
|







 







>










>
>







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

			continue
		}

		// Clearing e.length is not necessary as it will be overwritten later

		// Stage the complete byte for writing
		buffer := make([]byte, 1, 2)
		buffer[0] = byte(e.remaining)

		// Stage every full byte from the encoded value for writing
		//
		// The bitlength of the largest encoded byte value, 255, is 13.
		// Even with 7 bits already in the buffer this leaves [7+1], [8]
		// and 4 bits remaining => a single if is enough instead of a for.
		//
		// 128 is [1000 0000] in binary. Any value equal or greater than it
		// will be atleast 8 bits in length
		if enc >= 128 {
			buffer = append(buffer, byte(enc))
			enc >>= 8
			len -= 8
		}

		// Store the remaining bits
		e.remaining, e.length = byte(enc), len
................................................................................
		output[0] = byte(val)

		// Advance the internal and output buffers
		output = output[1:]
		d.buffer >>= len
		d.at -= len

		// Account for the processed output byte
		total++
	}

	// Termination condition
	if len(output) == 0 || err != nil {
		return total, err
	}

	// We need to limit the output's size else we could end up with a lot of small values
	// that fit neither in the output slice nor in the internal buffer
	//
	// (63 is [0011 1111] in binary, xor is a substraction and right shift a division)
	free := int((63 ^ d.at) >> 3)
	if free > len(output) {
		free = len(output)
	}

	// Read data and transfer to the internal buffer
	count, err := d.source.Read(output[:free])