On Monday, 8 June 2015 at 11:06:07 UTC, Daniel Kozák wrote:

On Mon, 08 Jun 2015 10:51:53 +0000
weaselcat via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

On Monday, 8 June 2015 at 10:49:59 UTC, Ilya Yaroshenko wrote:
> On Monday, 8 June 2015 at 10:42:00 UTC, Kadir Erdem Demir > wrote: >> I want to use my char array with awesome, cool >> std.algorithm functions. Since many of this algorithms >> requires like slicing etc.. I prefer to create my string >> with Utf32 chars. But by default all strings literals are >> Utf8 for performance.
>>
>> With my current knowledge I use to!dhar to convert >> Utf8[](or char[]) to Utf32[](or dchar[])
>>
>> dchar[] range = to!dchar("erdem".dup)
>>
>> How costly is this?
>> Is there a way which I can have Utf32 string directly >> without a cast?
>
> 1. dstring range = to!dstring("erdem"); //without dup
> 2. dchar[] range = to!(dchar[])("erdem"); //mutable
> 3. dstring range = "erdem"d; //directly
> 4. dchar[] range = "erdem"d.dup; //mutable

what's wrong with http://dlang.org/phobos/std_utf.html#.toUTF32

from: http://dlang.org/phobos/std_encoding.html#.transcode

Supersedes:
This function supersedes std.utf.toUTF8(), std.utf.toUTF16() and
std.utf.toUTF32() (but note that to!() supersedes it more conveniently).

BTW on ldc(ldc -O3 -singleobj -release -boundscheck=off) transcode is the fastest:

f0 time: 1 sec, 115 ms, 48 μs, and 7 hnsecs // to!dstring
f1 time: 449 ms and 329 μs // toUTF32
f2 time: 272 ms, 969 μs, and 1 hnsec // transcode

Reply via email to