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

List:       kde-commits
Subject:    [nepomuk-core/feature/resourcemanagercleanup] libnepomukcore/resource: Tidy up ResourceData::propert
From:       Simeon Bird <bladud () gmail ! com>
Date:       2013-03-16 20:59:45
Message-ID: 20130316205945.2BE87A604F () git ! kde ! org
[Download RAW message or body]

Git commit a442dda9e5327f2a1ee5f0346c4a8f476804650c by Simeon Bird.
Committed on 15/03/2013 at 04:17.
Pushed by sbird into branch 'feature/resourcemanagercleanup'.

Tidy up ResourceData::propertyAdded: if an entry is not found in a
QHash, it will return an empty list, so we only need to check for
contains one way.

M  +26   -39   libnepomukcore/resource/resourcedata.cpp

http://commits.kde.org/nepomuk-core/a442dda9e5327f2a1ee5f0346c4a8f476804650c

diff --git a/libnepomukcore/resource/resourcedata.cpp b/libnepomukcore/resource/resourcedata.cpp
index 1eb371f..9d7abe1 100644
--- a/libnepomukcore/resource/resourcedata.cpp
+++ b/libnepomukcore/resource/resourcedata.cpp
@@ -740,33 +740,29 @@ void Nepomuk2::ResourceData::updateKickOffLists(const QUrl& uri, const Nepomuk2:
 void Nepomuk2::ResourceData::propertyRemoved( const Types::Property &prop, const QVariant &value_ )
 {
     QMutexLocker lock(&m_dataMutex);
-    QHash<QUrl, Variant>::iterator cacheIt = m_cache.find(prop.uri());
-    if(cacheIt != m_cache.end()) {
-        Variant v = *cacheIt;
-        const Variant value(value_);
-        QList<Variant> vl = v.toVariantList();
-        if(vl.contains(value)) {
-            //
-            // Remove that element and and also remove all empty elements
-            // This is required because the value maybe have been a resource
-            // which has now been deleted, and no longer has a value
-            QMutableListIterator<Variant> it(vl);
-            while( it.hasNext() ) {
-                Variant var = it.next();
-                if( (var.isResource() && var.toUrl().isEmpty()) || var == value )
-                    it.remove();
-            }
-            if(vl.isEmpty()) {
-                updateKickOffLists(prop.uri(), m_cache.value(prop.uri()), Variant());
-                m_cache.erase(cacheIt);
-            }
-            else {
-                // The kickoff properties (nao:identifier and nie:url) both have a cardinality of 1
-                // If we have more than one value, then the properties must not be any of them
-                if( vl.size() == 1 )
-                    updateKickOffLists(prop.uri(), m_cache.value(prop.uri()), vl.first());
-                cacheIt.value() = vl;
-            }
+    const Variant value(value_);
+    QList<Variant> vl = m_cache.value(prop.uri()).toVariantList();
+    if( vl.contains(value) ) {
+        //
+        // Remove that element and and also remove all empty elements
+        // This is required because the value maybe have been a resource
+        // which has now been deleted, and no longer has a value
+        QMutableListIterator<Variant> it(vl);
+        while( it.hasNext() ) {
+            Variant var = it.next();
+            if( (var.isResource() && var.toUrl().isEmpty()) || var == value )
+                it.remove();
+        }
+        if(vl.isEmpty()) {
+            updateKickOffLists(prop.uri(), m_cache.value(prop.uri()), Variant());
+            m_cache.remove(prop.uri());
+        }
+        else {
+            // The kickoff properties (nao:identifier and nie:url) both have a cardinality of 1
+            // If we have more than one value, then the properties must not be any of them
+            if( vl.size() == 1 )
+                updateKickOffLists(prop.uri(), m_cache.value(prop.uri()), vl.first());
+            m_cache[prop.uri()] = vl;
         }
     }
 }
@@ -775,20 +771,11 @@ void Nepomuk2::ResourceData::propertyAdded( const Types::Property &prop, const Q
 {
     QMutexLocker lock(&m_dataMutex);
     const Variant var(value);
-    QHash<QUrl, Variant>::iterator cacheIt = m_cache.find(prop.uri());
-    if( cacheIt != m_cache.end() ) {
-        Variant v = *cacheIt;
-        QList<Variant> vl = v.toVariantList();
-        if( !vl.contains( var ) ) {
-            vl.append( var );
-            updateKickOffLists(prop.uri(), m_cache.value(prop.uri()), var);
-            cacheIt.value() = vl;
-        }
-    }
-    else {
-        updateKickOffLists(prop.uri(), m_cache.value(prop.uri()), var);
+    const Variant oldvalue = m_cache.value(prop.uri());
+    if( !oldvalue.toVariantList().contains(var) ) {
         m_cache[prop.uri()].append(var);
     }
+    updateKickOffLists(prop.uri(), oldvalue, var);
 }
 
 void Nepomuk2::ResourceData::setWatchEnabled(bool status)

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

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