Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Remove duplicated code, replaced with UpdateCRC. Funtion SlurpBlock. #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evo-i
Copy link

@evo-i evo-i commented Jul 30, 2024

Removed duplicated lines of code.
Replaced with UpdateCRC.

public void SlurpBlock(byte[] block, int offset, int count)
{
    if (block == null)
        throw new Exception("The data buffer must not be null.");

    // bzip algorithm
    for (int i = 0; i < count; i++)
    {
        int x = offset + i;
        byte b = block[x];
        if (this.reverseBits)
        {
            UInt32 temp = (_register >> 24) ^ b;
            _register = (_register << 8) ^ crc32Table[temp];
        }
        else
        {
            UInt32 temp = (_register & 0x000000FF) ^ b;
            _register = (_register >> 8) ^ crc32Table[temp];
        }
    }
    _TotalBytesRead += count;
}

Replaces with:

public void SlurpBlock(byte[] block, int offset, int count)
{
    if (block == null)
        throw new Exception("The data buffer must not be null.");

    // bzip algorithm
    for (int i = 0; i < count; i++)
    {
        int x = offset + i;
        byte b = block[x];
        UpdateCRC(b);
    }
    _TotalBytesRead += count;
}

Because UpdateCRC has:

public void UpdateCRC(byte b)
{
    if (this.reverseBits)
    {
        UInt32 temp = (_register >> 24) ^ b;
        _register = (_register << 8) ^ crc32Table[temp];
    }
    else
    {
        UInt32 temp = (_register & 0x000000FF) ^ b;
        _register = (_register >> 8) ^ crc32Table[temp];
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant