July 28, 2004
In article <ce8q1l$g6r$1@digitaldaemon.com>, parabolis says...
>
>Sean Kelly wrote:
>
>> parabolis wrote:
>> 
>>>
>>> But the general case is this horrible version:
>>>
>>> # for (int i=0; i>=String.length(); i++) { /* blah */ }
>>>   (call String.length(); every iteration)
>> 
>> 
>> Though I'm generally too prone to premature optimization to do this, I think the above code has the potential to be just as fast as the
>
>Emphasis on the potential. That means that you must first be able to guarantee that any compiler that gets your code will optimize it before you should feel safe writing it.

Perhaps I've been spoiled by the latest set of C++ compilers.  The tests I've seen with them tend to suggest that premature optimization often actually slows the resulting code down compared to what the optimizer can generate.

But the above example was pretty straightfoward.  I would be surprised if any production level D compiler didn't inline such calls.


Sean


July 28, 2004
"parabolis" <parabolis@softhome.net> escribió en el mensaje
news:ce8hhq$c9o$1@digitaldaemon.com
|
| I agree with you but you missed the multiple code units case
| where sort has the nice property that it /destroys/ a valid
| encoding:
| ================================================================
|      char threeInOrderCharacters[] = [
|          0xE6,0x97,0xA5,    // u+65E5
|          0xE6,0x9C,0xAC,    // u+672C
|          0xE8,0xAA,0x9E,    // u+8A9E
|      ];
|
|      void main(char[][] argv) {
|          uint max = threeInOrderCharacters.length;
|          threeInOrderCharacters.sort;
|          for( uint i = 0; i < max; i++ ) {
|          printf( "%2X ", threeInOrderCharacters[i] );
|      }
|      }
| ================================================================
|      Output:
|      97 9C 9E A5 AA AC E6 E6 E8
| ================================================================
|

Do what Jill said: use dchar.

/////////////////////////////
import std.utf;

char threeInOrderCharacters[] = [
    0xE6,0x97,0xA5,    // u+65E5
    0xE6,0x9C,0xAC,    // u+672C
    0xE8,0xAA,0x9E,    // u+8A9E
];

void main(char[][] argv) {
    dchar [] tIOC = toUTF32(threeInOrderCharacters);
    //uint max = threeInOrderCharacters.length;
    //threeInOrderCharacters.sort;
    tIOC.sort;
    char [] tIOC2 = toUTF8(tIOC);
    uint max = tIOC2.length;
    for( uint i = 0; i < max; i++ ) {
        //printf( "%2X ", threeInOrderCharacters[i] );
        printf( "%2X ", tIOC2[i] );
    }
}

/////////////////////////////

================================================================
     Output:
     E6 97 A5 E6 9C AC E8 AA 9E
================================================================

What you expected, right?
And, btw, using wchar gives the same result (and, of course, replacing toUTF32
by toUTF16).

-----------------------
Carlos Santander Bernal


1 2 3 4 5
Next ›   Last »