Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant