-
-
Notifications
You must be signed in to change notification settings - Fork 746
Re-add overload for fixed-size arrays to std.string.indexOf
#3191
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
Conversation
|
Hm.. I think this is not what was asked for. The original code did not instantiate a new template per static array size. This is kind of a very tricky issue, because you want to use The only good news here is that the template bloat should be minimal in terms of code size (the function should always inline), but it will hurt in the symbol table. If ever there was a case for I'm OK with this change, the template bloat should not be that bad. If others feel differently, I'd love to hear another solution. |
06e3ac8 to
3b386f8
Compare
|
I could factor the actual implementation out into a third, private template that is called by both of the others. But IMO it's not worth the trouble, and it would even make the common case worse, because it would instantiate two templates for each type. |
std/string.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use:
ref T[n] s
instead, otherwise the entire array gets copied to the stack!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, good catch!
yeah, agreed. |
3b386f8 to
97dddde
Compare
|
LGTM with latest changes. |
|
You'd think that having an overload receiving |
Re-add overload for fixed-size arrays to `std.string.indexOf`
|
This pull request introduced a regression: https://issues.dlang.org/show_bug.cgi?id=14735 |
|
Can someone figure this out? Removing the overload added in this PR makes it work, but this overload shouldn't match for the test case in the bug report, so I don't see how it could even have an effect. Is this a compiler bug? |
|
The problem has something to do with the |
|
Was this the only regression regarding static arrays of newly rangified functions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An optimization would be to use const(T)[], b/c of less template instantiations.
|
I think a better alternative would be to add explicit function overloads for void indexOf(Range)(Range s, in dchar c) @safe pure
{
pragma(msg, "Range "~Range.stringof);
}
void indexOf(const(char)[] s, in dchar c) @safe pure
{
pragma(msg, "const(char)[]");
.indexOf!(const(char)[])(s, c);
}
unittest
{
char[] ary;
char[128] sary;
indexOf(ary);
indexOf(sary);
} |
|
This is troublesome b/c of polysemeous string literals and conversion of other arguments. void test(const(char)[] s, in dchar c) {}
void test(const(dchar)[] s, in dchar c) {}
void test()
{
test("foo", 'a'); // 2nd arguments matches with conversion, so both overloads match equally well
} |
Fixed the regression introduced in #3172