| 253 | |
| 254 | |
| 255 | void Unpack::UnpWriteBuf() |
| 256 | { |
| 257 | size_t WrittenBorder=WrPtr; |
| 258 | size_t FullWriteSize=(UnpPtr-WrittenBorder)&MaxWinMask; |
| 259 | size_t WriteSizeLeft=FullWriteSize; |
| 260 | bool NotAllFiltersProcessed=false; |
| 261 | for (size_t I=0;I<Filters.Size();I++) |
| 262 | { |
| 263 | // Here we apply filters to data which we need to write. |
| 264 | // We always copy data to another memory block before processing. |
| 265 | // We cannot process them just in place in Window buffer, because |
| 266 | // these data can be used for future string matches, so we must |
| 267 | // preserve them in original form. |
| 268 | |
| 269 | UnpackFilter *flt=&Filters[I]; |
| 270 | if (flt->Type==FILTER_NONE) |
| 271 | continue; |
| 272 | if (flt->NextWindow) |
| 273 | { |
| 274 | // Here we skip filters which have block start in current data range |
| 275 | // due to address wrap around in circular dictionary, but actually |
| 276 | // belong to next dictionary block. If such filter start position |
| 277 | // is included to current write range, then we reset 'NextWindow' flag. |
| 278 | // In fact we can reset it even without such check, because current |
| 279 | // implementation seems to guarantee 'NextWindow' flag reset after |
| 280 | // buffer writing for all existing filters. But let's keep this check |
| 281 | // just in case. Compressor guarantees that distance between |
| 282 | // filter block start and filter storing position cannot exceed |
| 283 | // the dictionary size. So if we covered the filter block start with |
| 284 | // our write here, we can safely assume that filter is applicable |
| 285 | // to next block on no further wrap arounds is possible. |
| 286 | if (((flt->BlockStart-WrPtr)&MaxWinMask)<=FullWriteSize) |
| 287 | flt->NextWindow=false; |
| 288 | continue; |
| 289 | } |
| 290 | uint BlockStart=flt->BlockStart; |
| 291 | uint BlockLength=flt->BlockLength; |
| 292 | if (((BlockStart-WrittenBorder)&MaxWinMask)<WriteSizeLeft) |
| 293 | { |
| 294 | if (WrittenBorder!=BlockStart) |
| 295 | { |
| 296 | UnpWriteArea(WrittenBorder,BlockStart); |
| 297 | WrittenBorder=BlockStart; |
| 298 | WriteSizeLeft=(UnpPtr-WrittenBorder)&MaxWinMask; |
| 299 | } |
| 300 | if (BlockLength<=WriteSizeLeft) |
| 301 | { |
| 302 | if (BlockLength>0) // We set it to 0 also for invalid filters. |
| 303 | { |
| 304 | uint BlockEnd=(BlockStart+BlockLength)&MaxWinMask; |
| 305 | |
| 306 | FilterSrcMemory.Alloc(BlockLength); |
| 307 | byte *Mem=&FilterSrcMemory[0]; |
| 308 | if (BlockStart<BlockEnd || BlockEnd==0) |
| 309 | { |
| 310 | if (Fragmented) |
| 311 | FragWindow.CopyData(Mem,BlockStart,BlockLength); |
| 312 | else |