Re-add overload for fixed-size arrays to std.string.indexOf#3191
Re-add overload for fixed-size arrays to std.string.indexOf#3191WalterBright merged 1 commit intodlang:masterfrom
std.string.indexOf#3191Conversation
|
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.
use:
ref T[n] s
instead, otherwise the entire array gets copied to the stack!
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.
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