Pass NULL to data to make sure we have a mutable pointer into the stream. This can only work if we know the alignment of a stream and we are reading an aligned member with a size less than or equal to the stream's alignment
| 350 | // only work if we know the alignment of a stream and we are reading an aligned member |
| 351 | // with a size less than or equal to the stream's alignment |
| 352 | void* BlCvStreamReader::ReadFast(void* data, int size) |
| 353 | { |
| 354 | if (mCurBlockPos + size <= mCurBlockEnd) |
| 355 | { |
| 356 | // The FAST case, just return a pointer |
| 357 | void* ptr = mCurBlockPos; |
| 358 | mCurBlockPos += size; |
| 359 | return ptr; |
| 360 | } |
| 361 | |
| 362 | void* ptr = data; |
| 363 | while (mCurBlockPos + size > mCurBlockEnd) |
| 364 | { |
| 365 | int readBytes = (int)(mCurBlockEnd - mCurBlockPos); |
| 366 | if (readBytes > 0) |
| 367 | { |
| 368 | memcpy(data, mCurBlockPos, readBytes); |
| 369 | data = (uint8*)data + readBytes; |
| 370 | size -= readBytes; |
| 371 | } |
| 372 | |
| 373 | mBlockIdx++; |
| 374 | mCurBlockPos = (uint8*)mMsf->mBlocks[mCurStream->mBlocks[mBlockIdx]]->mData; |
| 375 | mCurBlockEnd = mCurBlockPos + CV_BLOCK_SIZE; |
| 376 | } |
| 377 | |
| 378 | // We had to load new data but nothing got read in yet |
| 379 | if (ptr == data) |
| 380 | { |
| 381 | void* ptr = mCurBlockPos; |
| 382 | mCurBlockPos += size; |
| 383 | return ptr; |
| 384 | } |
| 385 | |
| 386 | if (size > 0) |
| 387 | { |
| 388 | memcpy(data, mCurBlockPos, size); |
| 389 | mCurBlockPos += size; |
| 390 | } |
| 391 | |
| 392 | return ptr; |
| 393 | } |
| 394 | |
| 395 | void BlCvStreamReader::Seek(int size) |
| 396 | { |