Optimize internal calls to UnmarshalCBOR() for ByteString, RawTag, SimpleValue #647
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #646
This PR resolves a performance regression introduced and mentioned in PR #636 and #645:
This optimization avoids the redundant 2nd check of input data.
These functions are deprecated (they were created for internal use):
ByteString.UnmarshalCBOR()
RawTag.UnmarshalCBOR()
SimpleValue.UnmarshalCBOR()
Unmarshal()
should be used instead of the deprecated functions.Details
PR #636 and #645 cause the input data to be checked twice when these functions are called internally by
Unmarshal()
:ByteString.UnmarshalCBOR()
RawTag.UnmarshalCBOR()
SimpleValue.UnmarshalCBOR()
These functions check input data because they can be called by user apps providing bad data. However, the codec already checks input data before internally calling
UnmarshalCBOR()
so the 2nd check is redundant.This PR avoids redundant check on the input data by having
Unmarshal()
call the privateunmarshalCBOR()
implemented byByteString
,RawTag
,SimpleValue
:unmarshalCBOR()
to avoid the redundant check on input data.UnmarshalCBOR()
is available as a wrapper that checks input data before calling the privateunmarshalCBOR()
.To avoid breaking user apps, the 3
UnmarshalCBOR()
functions are deprecated rather than removed.