<commit_before>#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "isubject.h"
#include "interfaces/observer.h"

#include <qtl.h>

#include <kdebug.h>

namespace KMail {

  ISubject::~ISubject()
  {
    mObserverList.clear();
  }

  void ISubject::attach( Interface::Observer * pObserver )
  {
    if ( qFind( mObserverList.begin(), mObserverList.end(), pObserver ) == mObserverList.end() )
      mObserverList.push_back( pObserver );
  }

  void ISubject::detach( Interface::Observer * pObserver ) {
    QValueVector<Interface::Observer*>::iterator it = qFind( mObserverList.begin(), mObserverList.end(), pObserver );
    if ( it != mObserverList.end() )
      mObserverList.erase( it );
  }

  void ISubject::notify()
  {
    kdDebug(5006) << "ISubject::notify " << mObserverList.size() << endl;
    for ( QValueVector<Interface::Observer*>::iterator it = mObserverList.begin() ; it != mObserverList.end() ; ++it ) {
      if ( (*it) ) {
        (*it)->update( this );
      }
    }
  }

}

<commit_msg>ISubject: iterate over a copy of the observerlist<commit_after>#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "isubject.h"
#include "interfaces/observer.h"

#include <qtl.h>

#include <kdebug.h>

namespace KMail {

  ISubject::~ISubject()
  {
    mObserverList.clear();
  }

  void ISubject::attach( Interface::Observer * pObserver )
  {
    if ( qFind( mObserverList.begin(), mObserverList.end(), pObserver ) == mObserverList.end() )
      mObserverList.push_back( pObserver );
  }

  void ISubject::detach( Interface::Observer * pObserver ) {
    QValueVector<Interface::Observer*>::iterator it = qFind( mObserverList.begin(), mObserverList.end(), pObserver );
    if ( it != mObserverList.end() )
      mObserverList.erase( it );
  }

  void ISubject::notify()
  {
    kdDebug(5006) << "ISubject::notify " << mObserverList.size() << endl;

    // iterate over a copy (to prevent crashes when
    // {attach(),detach()} is called from an Observer::update()
    const QValueVector<Interface::Observer*> copy = mObserverList;
    for ( QValueVector<Interface::Observer*>::const_iterator it = copy.begin() ; it != copy.end() ; ++it ) {
      if ( (*it) ) {
        (*it)->update( this );
      }
    }
  }

}


{'fraction_non_alphanumeric': 0.16218637992831542, 'fraction_numerical': 0.0035842293906810036, 'mean_word_length': 3.710970464135021, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2312223', 'n_tokens_mistral': 771, 'n_tokens_neox': 751, 'n_words': 147}