Skip to content

[C#] BitUtility.cs performance improvement #45559

Open
@m-v-w

Description

@m-v-w

Describe the enhancement requested

The C# implementation of the BitUtility helper class seems to allocate an array every time GetBit is called:

private static ReadOnlySpan<byte> BitMask => new byte[] {
    1, 2, 4, 8, 16, 32, 64, 128
};
public static bool GetBit(ReadOnlySpan<byte> data, int index) =>
    (data[index / 8] & BitMask[index % 8]) != 0;

using a static cached BitMask array or creating the bit mask using a shift operator should increase performance.

Component(s)

C#

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions