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

Introduces TryGetDataLength in addition to GetDataLen. #115

Merged
merged 1 commit into from
Mar 17, 2020
Merged

Introduces TryGetDataLength in addition to GetDataLen. #115

merged 1 commit into from
Mar 17, 2020

Conversation

ycrumeyrolle
Copy link
Contributor

This method will not throw exception.
This is simplifying the flow, specificialy with the DecodeImpl that will catch the exception then return InvalidData value.

try
{
return this.DecodeImpl(ref src, srcLength, data, decodedLength, out consumed, out written, isFinalBlock);
}
catch (FormatException)
{
consumed = 0;
written = 0;
return OperationStatus.InvalidData;
}

The same pattern may also be replaced at

public override int GetMaxDecodedLength(int encodedLength)
{
try
{
return this.GetDecodedLength(encodedLength);
}
catch (FormatException)
{
// In the case of malformed input, i.e. wrong number of padding,
// just assume 2 padding chars and compute the data length.
// It's "max" anyway.
return (encodedLength + 2) / 4 * 3;
}
}

Benchmarks

No benchmark for the moment...

@gfoidl gfoidl added this to the v1.1.0 milestone Mar 17, 2020
@gfoidl gfoidl added the enhancement New feature or request label Mar 17, 2020
@gfoidl
Copy link
Owner

gfoidl commented Mar 17, 2020

Nice! 👍
This should improve perf, as there's no try-catch-block. I'm going to merge this, and try to tweak it a bit more in a follow-up pr.

Thank you!

@gfoidl gfoidl merged commit 7a04934 into gfoidl:master Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants