Removed auto-decoding from the floating point version of std.conv.parse#5015
Removed auto-decoding from the floating point version of std.conv.parse#5015JackStouffer merged 2 commits intodlang:masterfrom
Conversation
|
ping @andralex |
andralex
left a comment
There was a problem hiding this comment.
Yah this would be a lot easier to follow if it continued to use p...
|
|
||
| char sign = 0; /* indicating + */ | ||
| switch (p.front) | ||
| bool sign = false; |
| p.popFront(); | ||
| enforce(!p.empty, bailOut()); | ||
| if (toLower(p.front) == 'i') | ||
| sign = true; |
There was a problem hiding this comment.
Hmmm... looks like both the previous code and the current code are parsing --5 as positive 5, right?
There was a problem hiding this comment.
So I guess an enforce(!sign) is in order here. In fact sign should be a ternary: not seen, + seen, - seen.
std/conv.d
Outdated
| enforce(!p.empty, bailOut()); | ||
| if (toLower(p.front) == 'i') | ||
| sign = true; | ||
| source.popFront(); |
There was a problem hiding this comment.
(For simpler refactoring: continue using p and give the initial parameter a different name.)
std/conv.d
Outdated
| { | ||
| static if (isNarrowString!Source) | ||
| p = source.assumeUTF; | ||
|
|
There was a problem hiding this comment.
no reason for vertical space here
std/conv.d
Outdated
| static if (isNarrowString!Source) | ||
| p = source.assumeUTF; | ||
|
|
||
| return (sign) ? -0.0 : 0.0; |
std/conv.d
Outdated
| } | ||
|
|
||
| isHex = p.front == 'x' || p.front == 'X'; | ||
| isHex = source.front == 'x' || source.front == 'X'; |
There was a problem hiding this comment.
source.front.among('x', 'X') if it's convenient
std/conv.d
Outdated
|
|
||
| enforce(anydigits, bailOut()); | ||
| enforce(!p.empty && (p.front == 'p' || p.front == 'P'), | ||
| enforce(!source.empty && (source.front == 'p' || source.front == 'P'), |
e5fef35 to
a308446
Compare
|
Went back to |
|
Auto-merge toggled on |
|
Very nice! This should improve performance of conversions by std.conv.to from string to float or double, right? If that's the case, it might be worth including the std.conv.to benefit in the update notes. Might not be obvious. |
New version of #4674
13.5x faster! Code here.