metadataengine/server/src/mdsnotifier.cpp
changeset 23 33ae025ac1e8
parent 21 50bf9db68373
child 40 910a23996aa0
--- a/metadataengine/server/src/mdsnotifier.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsnotifier.cpp	Mon May 03 12:55:01 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.InsertInOrderAllowRepeats( 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,54 @@
 //
 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 );
+        }
     }
 
 // ------------------------------------------------
@@ -1335,6 +1368,10 @@
             	}
 	        }
 		}
-
 	}
 
+TInt CMdSNotifier::Compare( const TEntry& aFirst, const TEntry& aSecond )
+    {
+    return aFirst.Id() - aSecond.Id();
+    }
+