Skip to content

Conversation

jmdavis
Copy link
Member

@jmdavis jmdavis commented Feb 10, 2013

decodeFront was popping off elements from reference type ranges and input ranges but not other types. Ideally, it would act like decode and not pop any elements off of any range, but that doesn't work with input ranges. So, in order to keep it consistent, decodeFront now takes its range by ref and always pops off the code units that it decodes.

Also, the tests have been improved for decode, decodeFront, stride, and strideBack so that they test more range types (including reference types ranges).

static if (isRandomAccessRange!S && hasSlicing!S && hasLength!S)
str = str[numCodeUnits .. str.length];

return retval;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpicks here (though I realize 1 & 2 where prre-existing):

  1. Why does canIndex check for isSomeChar!(ElementType!S))?
  2. What is the point of immutable fst = str[0]; vs immutable fst = str.front;
  3. The last static if should re-use the definition of canIndex. As it stands, both are slightly different, and I can't tell if this is intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, canIndex shouldn't need to check for isSomeChar!(ElementType!S). It's probably left over from a previous refactoring. The difference between str[0] and str.front stems from an avoidance of front with strings, but since this is the overload which doesn't use strings, it shouldn't matter here (probably missed in a previous refactoring as well). The condition in the second static if is fine and is really what the first one should be. Functionally, this code is fine, but it does look like it could use to be cleaned up a bit more due to what you've pointed out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. That bit of code has been cleaned up.

@monarchdodra
Copy link
Collaborator

I reviewed the new code, and I have nothing to add (apart from the above mentioned nitpick).

I didn't look too much into the unittests.

jmdavis added 5 commits March 3, 2013 19:25
This change makes it so that decodeFront takes its range by ref and pops
off the code units that it decodes (unlike decode). It pretty much has
to do that, since it supports input ranges, and they can't do anything
else.
This makes no semantic difference to the code, but it makes it so that
the attributes which are on one of the overloads don't make it into the
documentation (where they would imply that all of the overloads have
those attributes, which is not correct).
@jmdavis
Copy link
Member Author

jmdavis commented Apr 23, 2013

Any more comments on this?

jmdavis added a commit that referenced this pull request Apr 28, 2013
Fix Issue 9456 -  decodeFront is inconsistent in whether it pops elements off of the range or not
@jmdavis jmdavis merged commit 3e60ef9 into dlang:master Apr 28, 2013
@jmdavis jmdavis deleted the decode branch January 28, 2018 01:27
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.

2 participants