metadataengine/client/src/mdeobjectdef.cpp
branchRCL_3
changeset 8 6752808b2036
parent 1 acef663c1218
child 14 646a02f170b9
--- a/metadataengine/client/src/mdeobjectdef.cpp	Tue Feb 02 00:24:33 2010 +0200
+++ b/metadataengine/client/src/mdeobjectdef.cpp	Fri Feb 19 23:14:48 2010 +0200
@@ -59,8 +59,9 @@
         {
 		aSchemaBuffer.PositionL( propertyOffset + i * sizeof(TMdCPropertyDef) );
 		const TMdCPropertyDef& propertyDef = TMdCPropertyDef::GetFromBufferL(aSchemaBuffer);
-		CMdEPropertyDef* propertyDefImpl = CMdEPropertyDef::NewL( propertyDef, aSchemaBuffer, *this );
-		iPropertyDefs.InsertInOrder( propertyDefImpl, TLinearOrder<CMdEPropertyDef>(CMdEObjectDef::CompareProperties) );
+		
+		CMdEPropertyDef* defImpl = CMdEPropertyDef::NewL( propertyDef, aSchemaBuffer, *this );
+		iPropertyDefs.InsertInOrder(defImpl, TLinearOrder<CMdEPropertyDef>(CMdEObjectDef::CompareProperties)); 
         }
     }
 
@@ -157,11 +158,48 @@
 
 CMdEPropertyDef* CMdEObjectDef::GetPropertyDefL(TDefId aId, CMdEObjectDef* aChild)
     {
-    const TInt i = iPropertyDefs.FindInOrder(aId, CMdEObjectDef::CompareProperties );
+    const TInt count = iPropertyDefs.Count();
+
+    TInt low( 0 );
+    TInt high( count );
+    TBool linearSearchRequired( EFalse );
     
-    if (i >= 0 && i < iPropertyDefs.Count() && iPropertyDefs[i] )
+    while( low < high )
         {
-        return iPropertyDefs[i];
+        TInt mid( (low+high)>>1 );
+        
+        if( !iPropertyDefs[mid] )
+            {
+            linearSearchRequired = ETrue;
+            break;
+            }
+        
+        TInt compare( aId - iPropertyDefs[mid]->Id() );
+        if( compare == 0 )
+            {
+            return iPropertyDefs[mid];
+            }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
+            }
+        }
+  
+    if( linearSearchRequired )
+        {
+        for ( TInt i = 0; i < count; ++i )
+            {
+            CMdEPropertyDef* propDef = iPropertyDefs[i];
+        
+            if( propDef && propDef->Id() == aId )
+                {
+                return propDef;
+                }
+            }
         }
 
     CMdEObjectDef* parent = ParentL();
@@ -189,13 +227,8 @@
 	return iPropertyDefs[aIndex];
 	}
 
-TInt CMdEObjectDef::CompareProperties( const CMdEPropertyDef& aFirst, const CMdEPropertyDef& aSecond )
+TInt CMdEObjectDef::CompareProperties(const CMdEPropertyDef& aFirst, const CMdEPropertyDef& aSecond)
     {
     return aFirst.Id() - aSecond.Id();
     }
 
-TInt CMdEObjectDef::CompareProperties( const TDefId* aFirst, const CMdEPropertyDef& aSecond )
-    {
-    return *aFirst - aSecond.Id();
-    }
-