| 266 | } |
| 267 | |
| 268 | ULONG Compressor::truncate(ULONG outLength) |
| 269 | { |
| 270 | /************************************** |
| 271 | * |
| 272 | * Reset to pack only a leading fragment of the input, restricted by the output length. |
| 273 | * Return the number of leading input bytes that fit the given output length. |
| 274 | * |
| 275 | **************************************/ |
| 276 | fb_assert(m_length > outLength); |
| 277 | |
| 278 | if (m_runs.isEmpty()) |
| 279 | { |
| 280 | m_length = outLength; |
| 281 | return outLength; |
| 282 | } |
| 283 | |
| 284 | auto space = (int) outLength; |
| 285 | ULONG inLength = 0; |
| 286 | ULONG keepRuns = 0; |
| 287 | m_length = 0; |
| 288 | |
| 289 | for (auto& length : m_runs) |
| 290 | { |
| 291 | if (--space <= 0) |
| 292 | break; |
| 293 | |
| 294 | if (length < 0) |
| 295 | { |
| 296 | const auto zipLength = (unsigned) -length; |
| 297 | const auto runLength = 1 + adjustRunLength(zipLength); |
| 298 | |
| 299 | if ((space -= runLength) < 0) |
| 300 | break; |
| 301 | |
| 302 | m_length += runLength + 1; |
| 303 | inLength += zipLength; |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | fb_assert(length > 0 && length <= MAX_NONCOMP_RUN); |
| 308 | |
| 309 | if ((space -= length) < 0) |
| 310 | { |
| 311 | length += space; // how many bytes fit |
| 312 | |
| 313 | m_length += length + 1; |
| 314 | inLength += length; |
| 315 | keepRuns++; |
| 316 | break; |
| 317 | } |
| 318 | |
| 319 | m_length += length + 1; |
| 320 | inLength += length; |
| 321 | } |
| 322 | |
| 323 | keepRuns++; |
| 324 | } |
| 325 |
nothing calls this directly
no test coverage detected