Check-in [27ecac81d3]
Overview
Comment:Calculate the decompressed block length outside of the predictor loop
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 27ecac81d3f5ae4317a83f1f2825010857b6b288
User & Date: spaskalev on 2014-12-22 17:15:41
Other Links: manifest | tags
Context
2014-12-22
19:28
Extracted the predictor's hash function as a method of the context struct. Minor changes to the decompressor's variables. check-in: 9dfd3cb1a2 user: spaskalev tags: trunk
17:15
Calculate the decompressed block length outside of the predictor loop check-in: 27ecac81d3 user: spaskalev tags: trunk
16:41
Integrate the decompressor2 branch into trunk now that it is faster. check-in: 6d10a1d28f user: spaskalev tags: trunk
Changes

Modified src/0dev.org/predictor/predictor.go from [71e92568a2] to [46cd9d5cef].

   169    169   		if rc < int(available) && err == nil {
   170    170   			// Retry the read if we have fewer bytes than what the prediction header indicates
   171    171   			var r int
   172    172   			r, err = reader.Read(ctx.input[predicted+rc:])
   173    173   			rc += r
   174    174   			goto retryData
   175    175   		} // Continue on any error, try to decompress and return it along the result
          176  +
          177  +		// rc now contains the amount of actual bytes in this cycle (usually 8)
          178  +		rc += predicted
   176    179   
   177    180   		// Walk the buffer, filling in the predicted blanks,
   178    181   		// relocating read bytes and and updating the guess table
   179         -		for i, a := uint(0), predicted; i < 8; i++ {
   180         -			if (flags & (1 << i)) > 0 {
          182  +		for i, a := 0, predicted; i < rc; i++ {
          183  +			if (flags & (1 << uint(i))) > 0 {
   181    184   				// Guess succeeded, fill in from the table
   182    185   				ctx.input[i] = ctx.table[ctx.hash]
   183         -				rc++
   184    186   			} else {
   185    187   				// Relocate a read byte
   186    188   				ctx.input[i], a = ctx.input[a], a+1
   187    189   				// Guess failed, update the table
   188    190   				ctx.table[ctx.hash] = ctx.input[i]
   189    191   			}
   190    192   			// Update the hash
   191    193   			ctx.hash = (ctx.hash << 4) ^ uint16(ctx.input[i])
   192    194   		}
   193    195   
   194         -		// rc now contains the precise amount of populated data
          196  +		// Copy the decompressed data to the output
   195    197   		ctx.input = ctx.input[:rc]
   196    198   		available = copy(output, ctx.input)
   197    199   
   198    200   		total += available
   199    201   
   200    202   		// Check for remaining bytes that dont fit in the output buffer
   201    203   		if available < rc {