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

Handle character ranges starting at '\x00' #8524

Closed
wants to merge 2 commits into from

Conversation

eschnett
Copy link
Contributor

Do not calculate start-1 unless needed; start-1 may not be well-defined.

Do not calculate start-1 unless needed; start-1 may not be well-defined.
@IainNZ
Copy link
Member

IainNZ commented Sep 29, 2014

May be some utility in adding a test for this

@kmsquire
Copy link
Member

Minor, but I would change it to an outer constructor and special case Char values. (That also means changing the existing outer constructor.)

@@ -62,7 +62,7 @@ immutable UnitRange{T<:Real} <: OrdinalRange{T,Int}
start::T
stop::T

UnitRange(start, stop) = new(start, ifelse(stop >= start, stop, start-1))
UnitRange(start, stop) = new(start, stop >= start ? stop : start-1)
Copy link
Member

Choose a reason for hiding this comment

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

I think start-1 should be convert(T, start-true) to avoid type instability and unnecessary checked conversion. This seems like it was an oversight in the previous code.

Also if we go this route and keep Char arithmetic checked, then we should check whether there's meaningful overhead to branching here instead of using ifelse. My guess is that there isn't, since the branch no longer interferes with inlining, in many cases the branch can be hoisted or eliminated, and in most remaining cases it should be predictable, but if there is meaningful overhead maybe we should keep using ifelse for Union(Signed, Unsigned). Or just implement coerce and use that.

@eschnett
Copy link
Contributor Author

The nearby class StepRange uses one(stop-start) instead of true (where both start and stop have the same type T). Should this then also be changed? Note that StepRange uses potentially a different type S for the step.

@JeffBezanson
Copy link
Member

I'm going to fix this a bit differently.

@eschnett eschnett deleted the char-range branch September 30, 2014 23:21
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.

5 participants