ecere/com: Avoid going through OnCopy() for units, bit classes and enums
authorJerome St-Louis <jerome@ecere.com>
Thu, 18 Dec 2014 18:08:02 +0000 (13:08 -0500)
committerJerome St-Louis <jerome@ecere.com>
Sun, 15 Feb 2015 20:33:15 +0000 (15:33 -0500)
ecere/src/com/containers/Map.ec
ecere/src/com/dataTypes.ec

index 74c55a1..4d5d19e 100644 (file)
@@ -203,7 +203,8 @@ public class Map<class MT, class V> : CustomAVLTree<MapNode<MT, V>, I = MT, D =
             node = MapNode<MT, V> { key = pos };
          }
          if((Tclass.type == systemClass && !Tclass.byValueSystemClass) || Tclass.type == bitClass || Tclass.type == enumClass || Tclass.type == unitClass)
-            onCopy(Tclass, (byte *)&node.key + __ENDIAN_PAD(Tclass.typeSize), (byte *)&pos + __ENDIAN_PAD(Tclass.typeSize));
+            // onCopy(Tclass, (byte *)&node.key + __ENDIAN_PAD(Tclass.typeSize), (byte *)&pos + __ENDIAN_PAD(Tclass.typeSize));
+            memcpy((byte *)&node.key + __ENDIAN_PAD(Tclass.typeSize), (byte *)&pos + __ENDIAN_PAD(Tclass.typeSize), Tclass.typeSize);
          else
             onCopy(Tclass, (byte *)&node.key + __ENDIAN_PAD(sizeof(void *)), (void *)pos);
          CustomAVLTree::AddEx((T)(uintptr)node, (T)(uintptr)addNode, addSide);
index d4812fd..644c40f 100644 (file)
@@ -1106,12 +1106,18 @@ static bool OnGetDataFromString(Class _class, void ** data, const char * string)
 
 static void OnCopy(Class _class, void ** data, void * newData)
 {
-   // TO IMPROVE: Inherit from Unit class for better performance?
    if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
    {
+      // An OnCopy is pointless for these, just copy the value
+      /*
       Class dataType = eSystem_FindClass(_class.module, _class.dataTypeString);
       if(dataType)
          ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, data, newData);
+      */
+      if(newData)
+         memcpy(data, newData, _class.typeSize);
+      else
+         memset(data, 0, _class.typeSize);
    }
    else if(_class.type != structClass && (_class.type != systemClass || _class.byValueSystemClass))
    {