metadataengine/server/src/mdsnotifier.cpp
branchRCL_3
changeset 8 50de4d668bb6
parent 7 3cebc1a84278
child 9 82c0024438c8
--- a/metadataengine/server/src/mdsnotifier.cpp	Mon Mar 15 12:42:24 2010 +0200
+++ b/metadataengine/server/src/mdsnotifier.cpp	Wed Mar 31 22:19:07 2010 +0300
@@ -465,10 +465,10 @@
     TConditionType aType, CMdCSerializationBuffer* aSerializedBuffer,
     TDefId aNamespaceDefId, CMdSServerSession& aSession, TBool aConfidential )
     {
-
-    User::LeaveIfError( iEntries.Append(
-        TEntry( aId, aType, aSerializedBuffer, aNamespaceDefId, aSession, aConfidential ) ) );
-    return iEntries[ iEntries.Count() - 1 ];
+    TEntry entry = TEntry( aId, aType, aSerializedBuffer, aNamespaceDefId, aSession, aConfidential ); 
+    User::LeaveIfError( iEntries.InsertInOrder( entry, TLinearOrder<TEntry>(CMdSNotifier::Compare) ) ); 
+    
+    return FindEntryL( aId );
     }
 
 // ------------------------------------------------
@@ -478,17 +478,29 @@
 CMdSNotifier::TEntry& CMdSNotifier::FindEntryL( TInt aId )
     {
     CMdSNotifier::TEntry* entry = NULL;
-    
-    const TInt count = iEntries.Count();
+
+    TInt low( 0 );
+    TInt high( iEntries.Count() );
     
-    for ( TInt i = 0; i < count; ++i )
+    while( low < high )
         {
-        if ( iEntries[i].iId == aId )
+        TInt mid( (low+high)>>1 );
+        
+        const TInt compare( aId - iEntries[mid].Id() );
+        if( compare == 0 )
             {
-            entry = &iEntries[i];
+            entry = &iEntries[mid];
             break;
             }
-        }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
+            }
+        }    
 
     if( !entry )
     	{
@@ -504,33 +516,55 @@
 //
 void CMdSNotifier::RemoveEntryL( TInt aId )
     {
-    const TInt count = iEntries.Count();
+    CMdSNotifier::TEntry* e = NULL;
+
+    TInt low( 0 );
+    TInt mid( 0 );
+    TInt high( iEntries.Count() );
     
-    for ( TInt i = 0; i < count; ++i )
+    while( low < high )
         {
-        TEntry& e = iEntries[i];
-        if ( e.iId == aId )
+        mid = (low+high)>>1;
+        
+        const TInt compare( aId - iEntries[mid].Id() );
+        if( compare == 0 )
             {
-            if ( e.IsPending() )
-                {
-                e.TriggerError( KErrCancel );
-                }
-            
-            if ( e.iSerializedCondition )
-            	{
-            	delete e.iSerializedCondition;
-            	e.iSerializedCondition = NULL;
-            	}
-            if ( e.iDataBuffer )
-            	{
-            	delete e.iDataBuffer;
-            	e.iDataBuffer = NULL;
-            	}
-            iEntries.Remove( i );
-            return;
+            e = &iEntries[mid];
+            break;
+            }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
             }
         }
-    User::Leave( KErrNotFound );
+    
+    if( e )
+        {
+        if ( e->IsPending() )
+            {
+            e->TriggerError( KErrCancel );
+            }
+    
+        if ( e->iSerializedCondition )
+            {
+            delete e->iSerializedCondition;
+            e->iSerializedCondition = NULL;
+            }
+        if ( e->iDataBuffer )
+            {
+            delete e->iDataBuffer;
+            e->iDataBuffer = NULL;
+            }
+        iEntries.Remove( mid );
+        }
+    else
+        {
+        User::Leave( KErrNotFound );
+        }
     }
 
 // ------------------------------------------------
@@ -637,12 +671,9 @@
                              matchingItemIdArray, matchingItemUriArray ) );    
                     }
             	}
-            // Copy of each uri is made to each client, which will own the returned uri
-            // Thus URI ownership is transferred and original array can be destroyed
-            matchingItemUriArray.ResetAndDestroy();
             }
 
-   		CleanupStack::PopAndDestroy( 2, &matchingItemIdArray );
+   		CleanupStack::PopAndDestroy( 2, &matchingItemIdArray ); // matchingItemIdArray, matchingItemUriArray
         }
     CleanupStack::PopAndDestroy( 2, &allItemsIdArray ); // allItemsIdArray, allItemsUriArray
     }
@@ -971,11 +1002,8 @@
                             matchingObjectIdArray, matchingItemUriArray ) );    
                     }
                 }
-            // Copy of each uri is made to each client, which will own the returned uri
-            // Thus URI ownership is transferred and original array can be destroyed
-            matchingItemUriArray.ResetAndDestroy();
             }
-		CleanupStack::PopAndDestroy( 2, &matchingObjectIdArray );
+		CleanupStack::PopAndDestroy( 2, &matchingObjectIdArray ); // matchingItemIdArray, matchingItemUriArray
         }
     CleanupStack::PopAndDestroy( 2, &allItemsIdArray ); // allItemsIdArray, allItemsUriArray
     }
@@ -1341,6 +1369,10 @@
             	}
 	        }
 		}
-
 	}
 
+TInt CMdSNotifier::Compare( const TEntry& aFirst, const TEntry& aSecond )
+    {
+    return aFirst.Id() - aSecond.Id();
+    }
+