Major performance problem with std.array.front()

Vladimir Panteleev vladimir at thecybershadow.net
Fri Mar 7 16:39:11 PST 2014


On Friday, 7 March 2014 at 19:57:38 UTC, Andrei Alexandrescu 
wrote:
> s.all!(x => x == 'é')
> s.any!(x => x == 'é')
> s.canFind!(x => x == 'é')

These are a variation of the following:

ubyte b = ...;
if (b == 1000) { ... }

The compiler could emit a warning here, and indeed some 
languages/compilers do. It might not be in the vein of D 
metaprogramming, though, as the compiler will not emit a warning 
for "if (false) { ... }".

> s.canFind('é')
> s.endsWith('é')
> s.find('é')
> s.count('é')
> s.countUntil('é')

These should not compile post-change, because the sought element 
(dchar) is not of the same type as the string. So they will not 
fail silently.

> s.count()
> s.count!((a, b) => std.uni.toLower(a) == 
> std.uni.toLower(b))("é")
> s.countUntil('é')

As has already been mentioned, counting code points is borderline 
useless.

> s.count!((a, b) => std.uni.toLower(a) == 
> std.uni.toLower(b))("é")

And this is just wrong on many levels. I hope you know better 
than to actually use this for case-insensitive comparisons in 
production software.


More information about the Digitalmars-d mailing list