[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KWrite Constructive Comments Welcome )
From:       David Faure <david () mandrakesoft ! com>
Date:       2000-09-01 14:09:10
[Download RAW message or body]

At 19:27 30/08/00 -0500, you wrote:
>Hello
>I am currently hacking away on the kwrite sources and have noticed that 
>loading a file seems to take a long time... a  1/2 Mb file seems to take 
>around 30-35 seconds from selection to display.
>
>I have bracketed the KWriteDoc->loadFile() function with a QTime object to 
>get some idea of the amount of time the loadFile takes and am getting around
>2800 msecs for the result of the original algorithm.
>I hacked a solution that I guess is around 20% faster and would like some 
>comments on the solution.
>This is the original code fragment
>// I changed stream.eof() which the trolls say is obselete
>  while ( !stream.atEnd() ) { 
>      stream >> ch;    
>      s = ch.latin1();
>      if (ch.isPrint() || s == '\t') {
>        textLine->append(&ch, 1);
>      } else if (s == '\n' || s == '\r') {
>        if (last != '\r' || s != '\n') {
>          textLine = new TextLine();
>          contents.append(textLine);
>          if (s == '\r') eolMode = eolMacintosh;
>        } else eolMode = eolDos;
>        last = s;
>      }
>And this is my solution  
>
>  while ( !stream.atEnd() ) {
>	QString iline=stream.readLine();
>	textLine=new TextLine();
>	eolMode =(iline[iline.length()]=='\r') ? eolMacintosh : eolDos;
>	textLine->replace(0,0,iline.unicode(),iline.length());
>	contents.append(textLine);
>  }
>
>I looked at the source for readline and from what I can gather the trolls 
>already check for /r /n 
>
>Can some one verify that 
>1.) this works same as orginal
>2.) that this is as fast or faster than orginal and
>3.) it is worth while to implement 

I would agree with 2 and 3. Using readLine seems a good idea to me.
But the above doesn't work like the original, at least for the eolMode.
Note that in the original code, eolMode could be Dos, Mac _or_ Unix.
(it's set to Unix by default, and changed only if \r\n (dos)
or \r (Mac), so in case of \n it remains Unix).

And IMHO checking for the mode at each line is a waste of time
(I know, the old code did that too, but let's optimise this :)

Looks like the algorithm should be something like

if mode not set yet (needs a new value in the enum, like Unknown)
  if length > 1 and last two chars are \r \n
     eolMode = eolDos;
  else
     eolMode =(iline[iline.length()]=='\r') ? eolMacintosh : eolUnix;

Thanks,
David.

 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic