ecere/containers/Array: Implemented faster deserialization
authorJerome St-Louis <jerome@ecere.com>
Sat, 4 Apr 2015 17:34:32 +0000 (13:34 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 15 Oct 2015 00:19:39 +0000 (20:19 -0400)
- Default Container implementation was doing 'count' reallocs

ecere/src/com/containers/Array.ec

index 748dd44..5079f7d 100644 (file)
@@ -7,6 +7,10 @@ import "Container"
 // #define MEMTRACKING
 #endif
 
+default:
+extern int __ecereVMethodID_class_OnUnserialize;
+private:
+
 public class Array : Container
 {
    class_fixed
@@ -21,6 +25,22 @@ public:
       delete array;
    }
 
+   void OnUnserialize(IOChannel channel)
+   {
+      Array array = eInstance_New(_class.fullName);
+      uint count, c;
+      Class Dclass = class(D);
+      channel.Get(count);
+      //printf("%d %ss\n", count, Dclass.name);
+      if(count > 10000)
+         printf("Bug");
+      array.size = count;
+      for(c = 0; c < count; c++)
+         ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
+            (Dclass, ((byte *)array.array) + Dclass.typeSize * c, channel);
+      this = array;
+   }
+
    // Generic iterator support
    IteratorPointer GetFirst() { return (IteratorPointer)array; }
    IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }