Skip to content

Comments

Removed auto-decoding from the floating point version of std.conv.parse#5015

Merged
JackStouffer merged 2 commits intodlang:masterfrom
JackStouffer:parse-decoding3
Jan 5, 2017
Merged

Removed auto-decoding from the floating point version of std.conv.parse#5015
JackStouffer merged 2 commits intodlang:masterfrom
JackStouffer:parse-decoding3

Conversation

@JackStouffer
Copy link
Contributor

New version of #4674

13.5x faster! Code here.

# new
$ ldc2 -O5 -release test.d && ./test
Total time: 387 ms, 506 μs, and 8 hnsecs

# old
$ ldc2 -O5 -release test.d && ./test
Total time: 5 secs, 238 ms, 59 μs, and 4 hnsecs

@JackStouffer
Copy link
Contributor Author

ping @andralex

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

ah, nice

p.popFront();
enforce(!p.empty, bailOut());
if (toLower(p.front) == 'i')
sign = true;
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm... looks like both the previous code and the current code are parsing --5 as positive 5, right?

Copy link
Member

Choose a reason for hiding this comment

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

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();
Copy link
Member

Choose a reason for hiding this comment

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

(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;

Copy link
Member

Choose a reason for hiding this comment

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

no reason for vertical space here

std/conv.d Outdated
static if (isNarrowString!Source)
p = source.assumeUTF;

return (sign) ? -0.0 : 0.0;
Copy link
Member

Choose a reason for hiding this comment

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

drop the parens

Copy link
Member

Choose a reason for hiding this comment

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

cc @wilzbach :)

std/conv.d Outdated
}

isHex = p.front == 'x' || p.front == 'X';
isHex = source.front == 'x' || source.front == 'X';
Copy link
Member

Choose a reason for hiding this comment

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

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'),
Copy link
Member

Choose a reason for hiding this comment

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

among could be of use again

@JackStouffer
Copy link
Contributor Author

JackStouffer commented Jan 5, 2017

Went back to p so the diff is now much smaller

@JackStouffer
Copy link
Contributor Author

Auto-merge toggled on

@JackStouffer JackStouffer merged commit dae2040 into dlang:master Jan 5, 2017
@jondegenhardt
Copy link
Contributor

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.

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.

3 participants