EDA/SQLite: Collation comparison optimization
authorJerome St-Louis <jerome@ecere.com>
Wed, 9 Dec 2015 23:20:00 +0000 (18:20 -0500)
committerJerome St-Louis <jerome@ecere.com>
Wed, 2 Nov 2016 16:32:37 +0000 (12:32 -0400)
- Using a static buffer (watch out for EDASQLite/threads usage)

eda/drivers/sqlite/EDASQLite.ec

index aff0ae9..a168e28 100644 (file)
@@ -40,6 +40,11 @@ extern int __ecereVMethodID_class_OnUnserialize;
 extern int __ecereVMethodID_class_OnFree;
 private:
 
+static SerialBuffer collationBuffer1 { };
+static SerialBuffer collationBuffer2 { };
+static char storage1[512];
+static char storage2[512];
+
 int CollationCompare(Class type, int count1, const void * data1, int count2, const void * data2)
 {
    if(type.type == normalClass || type.type ==  noHeadClass)
@@ -66,11 +71,30 @@ int CollationCompare(Class type, int count1, const void * data1, int count2, con
    {
       void * inst1, * inst2;
       int result;
-      SerialBuffer buffer1 { size = count1, count = count1, buffer = (byte *)data1 };
-      SerialBuffer buffer2 { size = count2, count = count2, buffer = (byte *)data2 };
-
-      inst1 = new0 byte[type.structSize];
-      inst2 = new0 byte[type.structSize];
+      //SerialBuffer buffer1 { size = count1, count = count1, buffer = (byte *)data1 };
+      //SerialBuffer buffer2 { size = count2, count = count2, buffer = (byte *)data2 };
+
+      SerialBuffer buffer1 = collationBuffer1;
+      SerialBuffer buffer2 = collationBuffer2;
+      buffer1.buffer = (byte*)data1;
+      buffer1.size = count1;
+      buffer1.count = count1;
+      buffer1.pos = 0;
+      buffer2.buffer = (byte*)data2;
+      buffer2.size = count2;
+      buffer2.count = count2;
+      buffer2.pos = 0;
+
+      if(type.structSize > 512)
+      {
+         inst1 = new0 byte[type.structSize];
+         inst2 = new0 byte[type.structSize];
+      }
+      else
+      {
+         inst1 = storage1;
+         inst2 = storage2;
+      }
       ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, inst1, buffer1);
       ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, inst2, buffer2);
 
@@ -78,10 +102,13 @@ int CollationCompare(Class type, int count1, const void * data1, int count2, con
 
       buffer1.buffer = null;
       buffer2.buffer = null;
-      delete buffer1;
-      delete buffer2;
-      delete inst1;
-      delete inst2;
+      //delete buffer1;
+      //delete buffer2;
+      if(type.structSize > 512)
+      {
+         delete inst1;
+         delete inst2;
+      }
       return result;
    }
    else