Skip to content

Conversation

@rv32ima
Copy link
Member

@rv32ima rv32ima commented Aug 11, 2021

Adds in support for hex literals with underscores for better readability. Should not change the existing behavior, but added several unit-tests to verify that the underscore literals are equivalent to non-underscore literals.

Note: in static BigUIntView fromHexString(), we actually over-allocate for the amount of coefficients that we need

auto length = str.length / (W.sizeof * 2) + (str.length % (W.sizeof * 2) != 0);

This is sliced down to the amount that was actually taken here (where j represents the number of non-underscore characters)

coefficients = coefficients[0 .. (j / (W.sizeof * 2) + (j % (W.sizeof * 2) != 0))];

This does increase the initial memory footprint (especially as the input string gets longer), but I haven't been able to think of a good way to get around this while keeping fromHexStringImpl @nogc. Ideally, I want to avoid iterating through the whole string twice, but that seems like the only solution that seems feasible to me.

@9il
Copy link
Member

9il commented Aug 12, 2021

This does increase the initial memory footprint (especially as the input string gets longer), but I haven't been able to think of a good way to get around this while keeping fromHexStringImpl @nogc. Ideally, I want to avoid iterating through the whole string twice, but that seems like the only solution that seems feasible to me.

It is OK to overallocate here.

@rv32ima
Copy link
Member Author

rv32ima commented Aug 16, 2021

Unified all of the fail cases into one, added more test-cases (including ones where an underscore is at the beginning)

@9il 9il merged commit 0f8e514 into master Aug 16, 2021
@9il 9il deleted the add-hex-literal-underscores branch August 16, 2021 14:45
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.

3 participants