]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/unix/filemonitor.cpp
Use C++11 features with containers
[libs/core.git] / source / fs / unix / filemonitor.cpp
index e2ca3b74ebcde44bcc85f562e67ea20d989074a4..11b2a8d74b1705ba4b16c38d447e7c8e9516fdb7 100644 (file)
@@ -1,5 +1,6 @@
 #include <sys/inotify.h>
 #include <linux/limits.h>
+#include <msp/core/algorithm.h>
 #include <msp/core/systemerror.h>
 #include <msp/io/handle_private.h>
 #include "filemonitor.h"
@@ -99,27 +100,26 @@ void FileMonitor::Private::events_available()
        for(unsigned i=0; i<len; )
        {
                struct inotify_event *event = reinterpret_cast<struct inotify_event *>(event_buf+i);
-               for(vector<MonitoredFile>::iterator j=monitor.files.begin(); j!=monitor.files.end(); ++j)
-                       if(j->tag==event->wd)
+               auto j = find_member(monitor.files, event->wd, &MonitoredFile::tag);
+               if(j!=monitor.files.end())
+               {
+                       if(event->mask&IN_MODIFY)
+                               j->modified = true;
+                       if(((event->mask&IN_CLOSE_WRITE) && j->modified) || (event->mask&IN_DELETE_SELF))
                        {
-                               if(event->mask&IN_MODIFY)
-                                       j->modified = true;
-                               if(((event->mask&IN_CLOSE_WRITE) && j->modified) || (event->mask&IN_DELETE_SELF))
-                               {
-                                       j->modified = false;
-                                       changed_files.push_back(j->path);
-                               }
-                               if(event->mask&IN_IGNORED)
-                                       j->tag = -1;
-                               break;
+                               j->modified = false;
+                               changed_files.push_back(j->path);
                        }
+                       if(event->mask&IN_IGNORED)
+                               j->tag = -1;
+               }
                i += sizeof(struct inotify_event)+event->len;
        }
 
-       for(vector<FS::Path>::const_iterator i=changed_files.begin(); i!=changed_files.end(); ++i)
-               monitor.signal_file_modified.emit(*i);
+       for(const FS::Path &p: changed_files)
+               monitor.signal_file_modified.emit(p);
 
-       for(vector<MonitoredFile>::iterator j=monitor.files.begin(); j!=monitor.files.end(); )
+       for(auto j=monitor.files.begin(); j!=monitor.files.end(); )
        {
                if(j->tag==-1)
                        monitor.files.erase(j++);