Fix the bugs of manual_memcpy
, simplify the suggestion and refactor it
#5536
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.
While I’m working on the long procrastinated work to expand
manual_memcpy
(#1670), I found a few minor bugs and probably unidiomatic or old coding style. There is a brief explanation of changes to the behaviour this PR will make below. And, I have a questoin: do I need to add tests for the first and second fixed bugs? I thought it might be too rare cases to include the tests for those. I added for the last one though.Bug fix
It negates resulted offsets (
src/dst_offset
) whenoffset
is subtraction by 0. This PR will remove any subtraction by 0 as a part of minification.It prints
RangeTo
orRangeFull
when both ofend
andoffset
are 0, which have different meaning. This PR will print 0. I could reject the casesend
is 0, but I thought I won’t catch other casesreverse_range_loop
will trigger, and it’s over to catch every such cases.it prints four dots when
end
isNone
. This PR will ignore anyfor
loops withoutend
because afor
loop that takesRangeFrom
as its argument and contains indexing without the statements or the expressions that end loops such asbreak
will definitely panic, andmanual_memcpy
should ignore the loops with such control flow.Simplification of the suggestion
start
orend
andoffset
are same (from Simplify manual_memcpy suggestion in some cases #3323). This PR will useRangeTo
changelog: fixed the bugs of
manual_memcpy
and also simplify the suggestion.