Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 1951

Show
Ignore:
Timestamp:
03/22/07 04:03:11 (2 years ago)
Author:
kris
Message:

optimized nextLine() for jollies

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/io/Console.d

    r1950 r1951  
    1919private import  tango.io.Buffer, 
    2020                tango.io.DeviceConduit; 
     21 
     22 
     23version (Opt) 
     24{ 
     25private uint indexOf (void* str, char match, uint length) 
     26{ 
     27        version (D_InlineAsm_X86) 
     28        {        
     29                        asm { 
     30                            mov   EDI, str; 
     31                            mov   ECX, length; 
     32                            movzx EAX, match; 
     33                            mov   ESI, ECX; 
     34                            and   ESI, ESI;             
     35                            jz    end;         
     36 
     37                            cld; 
     38                            repnz; 
     39                            scasb; 
     40                            jnz   end; 
     41                            sub   ESI, ECX; 
     42                            dec   ESI; 
     43                        end:; 
     44                            mov   EAX, ESI; 
     45                            } 
     46        } 
     47        else 
     48        { 
     49                auto len = length; 
     50                for (auto p=str-1; len--;) 
     51                     if (*++p is match) 
     52                         return p - str; 
     53                return length; 
     54        } 
     55} 
     56} 
    2157 
    2258/******************************************************************************* 
     
    115151                bool nextLine (inout char[] content, bool raw=false) 
    116152                { 
     153version (Opt) 
     154{ 
     155                        uint scan (void[] input) 
     156                        { 
     157                                auto i = indexOf (input.ptr, '\n', input.length); 
     158                                if (i < input.length) 
     159                                   { 
     160                                   ++i; 
     161                                   content = cast(char[])cast(void*) input [0..i]; 
     162                                   return i; 
     163                                   } 
     164                                content = cast(char[])cast(void*) input; 
     165                                return IConduit.Eof; 
     166                        } 
     167} 
     168else 
     169{ 
    117170                        uint scan (void[] input) 
    118171                        { 
     
    133186                                return IConduit.Eof; 
    134187                        } 
     188} 
    135189 
    136190                        return buffer_.next (&scan) || content.length; 
     
    318372 
    319373                        *******************************************************/ 
    320  
     374/+ 
    321375                        uint bufferSize () 
    322376                        { 
    323377                                return 1024 * 8; 
    324378                        } 
    325  
     379+/ 
    326380                        /******************************************************* 
    327381