On 21.09.2011 19:12, Christophe Travert wrote:
Nice. It is better with gdc linux 64bits too. I wanted to avoid
conditional expressions like ?: but it's actually slightly faster that
way.
It is not compiled in as conditional jump.
> Here is a more readable and a bit faster version on dmd windows:
>
> size_t utfCount(string text)
> {
> size_t n = 0;
> for (uint i=0; i n += ((text[i]>>6)^0b10)? 1: 0;
> return n;
> }
Nice. It is better with gdc linux 64bits too. I wanted to avoid
conditional expressi
On 21.09.2011 18:47, Christophe wrote:
Actually, I don't buy it. I guess the reason it's faster is that it
doesn't check if the codepoint is valid.
Why should it ? The documentation of std.utf.count says the string must
be validly encoded, not that it will enforce that it is.
Checking a string
On 21.09.2011 01:57, Christophe wrote:
size_t myCount(string text)
{
size_t n = text.length;
for (uint i=0; i>6;
n -= (s>>1) - ((s+1)>>2);
}
return n;
}
Here is a more readable and a bit faster version on dmd windows:
size_t utfCount(string text)
{
size_t n = 0;
> Actually, I don't buy it. I guess the reason it's faster is that it
> doesn't check if the codepoint is valid.
Why should it ? The documentation of std.utf.count says the string must
be validly encoded, not that it will enforce that it is.
Checking a string is valid everytime you use it would
On 09/21/2011 12:37 PM, Dmitry Olshansky wrote:
On 21.09.2011 4:04, Timon Gehr wrote:
On 09/21/2011 01:57 AM, Christophe wrote:
"Jonathan M Davis" , dans le message (digitalmars.D.learn:29637), a
écrit :
On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote:
On 9/20/11, Jonathan M Davis
On 09/21/2011 02:15 AM, Christophe wrote:
Timon Gehr , dans le message (digitalmars.D.learn:29641), a écrit :
Last point: WalkLength is not optimized for strings.
std.utf.count should be.
This short implementation of count was 3 to 8 times faster than
walkLength is a simple benchmark:
size_t m
On 21.09.2011 4:04, Timon Gehr wrote:
On 09/21/2011 01:57 AM, Christophe wrote:
"Jonathan M Davis" , dans le message (digitalmars.D.learn:29637), a
écrit :
On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote:
On 9/20/11, Jonathan M Davis wrote:
Or std.range.walkLength. I don't know why
Timon Gehr , dans le message (digitalmars.D.learn:29641), a écrit :
>> Last point: WalkLength is not optimized for strings.
>> std.utf.count should be.
>>
>> This short implementation of count was 3 to 8 times faster than
>> walkLength is a simple benchmark:
>>
>> size_t myCount(string text)
>> {
>
On 09/21/2011 01:57 AM, Christophe wrote:
"Jonathan M Davis" , dans le message (digitalmars.D.learn:29637), a
écrit :
On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote:
On 9/20/11, Jonathan M Davis wrote:
Or std.range.walkLength. I don't know why we really have std.utf.count. I
jus
"Jonathan M Davis" , dans le message (digitalmars.D.learn:29637), a
écrit :
> On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote:
>> On 9/20/11, Jonathan M Davis wrote:
>> > Or std.range.walkLength. I don't know why we really have std.utf.count. I
>> > just
>> > calls walkLength anyway. I
On Tuesday, September 20, 2011 15:10 Andrej Mitrovic wrote:
> On 9/20/11, Jonathan M Davis wrote:
> > We specifically avoid having aliases in Phobos simply for having
> > alternate function names. Aliases need to actually be useful, or they
> > shouldn't be there.
>
> And function names have to b
On 9/20/11, Jonathan M Davis wrote:
> We specifically avoid having aliases in Phobos simply for having alternate
> function names. Aliases need to actually be useful, or they shouldn't be
> there.
And function names have to be useful to library users. walkLength is
an awful name for something tha
On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote:
> On 9/20/11, Jonathan M Davis wrote:
> > Or std.range.walkLength. I don't know why we really have std.utf.count. I
> > just
> > calls walkLength anyway. I suspect that it's a function that predates
> > walkLength and was made to use walk
One other thing, count can only take an array which seems too
restrictive since walkLength can take any range at all. So maybe count
should be just an alias to walkLength or it should possibly be removed
(I'm against fully removing it because I already use it in code and I
think the name does make
On 9/20/11, Jonathan M Davis wrote:
> Or std.range.walkLength. I don't know why we really have std.utf.count. I
> just
> calls walkLength anyway. I suspect that it's a function that predates
> walkLength and was made to use walkLength after walkLength was introduced.
> But
> it's kind of pointless
On Tuesday, September 20, 2011 14:27 Andrej Mitrovic wrote:
> Don't use length, use std.utf.count, ala:
>
> import std.utf;
> alias toUTFz!(const(wchar)*, string) toUTF16z;
> GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s);
Or std.range.walkLength. I don't know why we really have std.u
Don't use length, use std.utf.count, ala:
import std.utf;
alias toUTFz!(const(wchar)*, string) toUTF16z;
GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s);
I like to keep that alias for my code since I was already using it beforehand.
I'm pretty sure (ok maybe 80% sure) that GetTextExt
Am Tue, 20 Sep 2011 20:44:40 +0200 schrieb Timon Gehr:
> On 09/20/2011 08:24 PM, Timon Gehr wrote:
>> On 09/20/2011 08:07 PM, Andre wrote:
>>> Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
>>>
> bool test(HDC dc, string str, int len, SIZE* s)
> {
> wchar[] wstr = toUTFz!(wchar*)s
On 09/20/2011 08:24 PM, Timon Gehr wrote:
On 09/20/2011 08:07 PM, Andre wrote:
Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
bool test(HDC dc, string str, int len, SIZE* s)
{
wchar[] wstr = toUTFz!(wchar*)str;
GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
toUTFz returns a wchar*,
On 09/20/2011 08:34 PM, Trass3r wrote:
Are you sure that the call requires the string to be null terminated?
I do not know that winapi function, but this might work:
bool test(HDC dc, string str, SIZE* s)
{
auto wstr = to!(wchar[])str;
GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
...
I
Are you sure that the call requires the string to be null terminated? I
do not know that winapi function, but this might work:
bool test(HDC dc, string str, SIZE* s)
{
auto wstr = to!(wchar[])str;
GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
...
It doesn't need to be null-terminated f
On 09/20/2011 08:07 PM, Andre wrote:
Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
bool test(HDC dc, string str, int len, SIZE* s)
{
wchar[] wstr = toUTFz!(wchar*)str;
GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
toUTFz returns a wchar*, not a wchar[].
I am not familiar with po
Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
>> bool test(HDC dc, string str, int len, SIZE* s)
>> {
>> wchar[] wstr = toUTFz!(wchar*)str;
>> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
>
> toUTFz returns a wchar*, not a wchar[].
I am not familiar with pointers. I know I have to
c
bool test(HDC dc, string str, int len, SIZE* s)
{
wchar[] wstr = toUTFz!(wchar*)str;
GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
toUTFz returns a wchar*, not a wchar[].
25 matches
Mail list logo