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

List:       kde-commits
Subject:    Re: branches/KDE/3.5/kdelibs/kate/part
From:       "Guillermo A. Amaral" <me () guillermoamaral ! com>
Date:       2007-06-17 22:52:39
Message-ID: 200706171552.44280.me () guillermoamaral ! com
[Download RAW message or body]


On Sunday 17 June 2007, Leo Savernik wrote:
> Am Sonntag, 17. Juni 2007 schrieb Guillermo Antonio Amaral Bastidas:
> >   void KateDocument::updateModified()
> >   {
> > -   if ( ( lastUndoGroupWhenSaved &&
> > -             !undoItems.isEmpty() &&
> > -             undoItems.last() == lastUndoGroupWhenSaved )
> > -          || ( undoItems.isEmpty() && docWasSavedWhenUndoWasEmpty ) )
> > +   // I noticed that there to many variables to take into consideration
> > +   // with a simple 'if' or two.
> > +   //
> > +   // Patterns Detected:
> > +   //
> > +   //   pattern=223   1==7:true   1==8:false   2==7:false   2==8:false
> > +   //   pattern=201   1==7:true   1==8:false   2==7:false   2==8:false
> > +   //   pattern=195   1==7:true   1==8:false   2==7:false   2==8:true
> > +   //   pattern=105   1==7:true   1==8:false   2==7:false   2==8:true
> > +   //   pattern=148   1==7:false 1==8:false   2==7:false   2==8:false
> > +   //   pattern=156   1==7:false 1==8:false   2==7:false   2==8:false
> > +   //   pattern=149   1==7:false 1==8:true    2==7:false   2==8:false
> > +
> > +   unsigned char pattern = 0;
> > +   const bool oneEqualToSeven = (lastUndoGroupWhenSaved ==
> > undoItems.last()); +   const bool oneEqualToEight =
> > (lastUndoGroupWhenSaved == redoItems.last()); +   const bool
> > twoEqualToSeven =
> > (lastRedoGroupWhenSaved == undoItems.last()); +   const bool
> > twoEqualToEight = (lastRedoGroupWhenSaved == redoItems.last()); +   bool
> > doModify = false; +
> > +   if (lastUndoGroupWhenSaved) pattern |= 1;
> > +   if (lastRedoGroupWhenSaved) pattern |= 2;
> > +   if (docWasSavedWhenUndoWasEmpty) pattern |= 4;
> > +   if (docWasSavedWhenRedoWasEmpty) pattern |= 8;
> > +   if (undoItems.isEmpty()) pattern |= 16;
> > +   if (redoItems.isEmpty()) pattern |= 32;
> > +   if (undoItems.last()) pattern |= 64;
> > +   if (redoItems.last()) pattern |= 128;
> > +
> > +   switch (pattern)
> >      {
> > +      case 223: case 201:
> > +            doModify = (oneEqualToSeven);
> > +         break;
> > +
> > +      case 195: case 105:
> > +            doModify = (oneEqualToSeven && twoEqualToEight);
> > +         break;
> > +
> > +      case 148: case 156:
> > +            doModify = true;
> > +         break;
> > +
> > +      case 149: case 151:
> > +            doModify = (oneEqualToEight);
> > +         break;
> > +   }   
> > +
> > +   if (doModify)
> > +   {
> >         setModified( false );
> >         kdDebug(13020) << k_funcinfo << "setting modified to false!" <<
> > endl; };
> > +
> > +   kdDebug(13020) << k_funcinfo << "pattern=" << static_cast<unsigned
> > int>(pattern) << " 1==7:" << oneEqualToSeven +   << " 1==8:" <<
> > oneEqualToEight << " 2==7:" << twoEqualToSeven << " 2==8:" <<
> > twoEqualToEight << endl; }
>
> This may fix the bug, but it's not actually maintainable code. Is this some
> kind of autogenerated stuff? How did you produce it?
>
> mfg
> 	Leo

  Well I just tested for all possible scenarios I could think of for requiring 
the modified flag to be unset ("false") and after comming up with a rather 
large "if" expression with many repetitive time consuming calls, I came up 
with this baby after noticing that I had just 8 things to check for and 8 
bits in a byte ( used to work as an algorithm specialist in my old job), I 
wrote it all from scratch and I made it as simple and as possible, so if a 
new bug like this one presents it self in the future you only need to add 
the "pattern" number from the debug print out to one of the switch case's or 
add a new case if it is required by the bug.

-- 
Guillermo A. Amaral, CSE
# Free & Open Source Advocate
& nick: guillermoamaral
@ blog: http://blog.guillermoamaral.com/
@ site: http://www.guillermoamaral.com/
$ irc: guillermoamaral@freenode
% gpg: http://downloads.guillermoamaral.com/public.asc

["signature.asc" (application/pgp-signature)]

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

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