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

Patch to prevent requiring memchr at compile time #1293

Closed
wants to merge 2 commits into from
Closed

Patch to prevent requiring memchr at compile time #1293

wants to merge 2 commits into from

Conversation

kothar
Copy link

@kothar kothar commented May 17, 2013

See http://d.puremagic.com/issues/show_bug.cgi?id=10078 for full description.

If the std.string.indexOf(Char[], dchar, CaseSensitive) method is called at compile time with an ASCII dchar, it will fail:

/usr/share/dmd/src/phobos/std/string.d(345): 
    Error: memchr cannot be interpreted at compile time, 
    because it has no available source code

{
if (c1 == c2)
return i;
}
Copy link
Member

Choose a reason for hiding this comment

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

memchr is a heavily optimized function, and will be faster than doing it with a naïve loop. To make it work with ctfe yet keep the memchr, use:

if (__ctfe)
    ... loop ...
else
    ... memchr ...

@kothar
Copy link
Author

kothar commented May 18, 2013

Any better? I should have realised that, but of course was fixing it for myself rather than looking at the bigger picture!

{
if (c1 == c2)
return i;
}
Copy link
Member

Choose a reason for hiding this comment

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

The control flow of this function is structured terribly, but if you don't want to rewrite the whole function you should return -1 here.

@MartinNowak
Copy link
Member

superseded by #1417

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