瀏覽代碼

improve transferRowsCopy

Jake Smith 12 年之前
父節點
當前提交
f2fa68ad0b
共有 3 個文件被更改,包括 29 次插入35 次删除
  1. 3 5
      thorlcr/activities/msort/thsortu.cpp
  2. 20 29
      thorlcr/thorutil/thmem.cpp
  3. 6 1
      thorlcr/thorutil/thmem.hpp

+ 3 - 5
thorlcr/activities/msort/thsortu.cpp

@@ -1400,9 +1400,11 @@ ILimitedCompareHelper *createLimitedCompareHelper()
 
 //===============================================================
 
-class CMultiCoreJoinHelperBase: extends CInterface, implements IJoinHelper, implements IMulticoreIntercept
+class CMultiCoreJoinHelperBase: extends CSimpleInterface, implements IJoinHelper, implements IMulticoreIntercept
 {
 public:
+    IMPLEMENT_IINTERFACE_USING(CSimpleInterface);
+
     CActivityBase &activity;
     IRowInterfaces *rowIf;
     IJoinHelper *jhelper;
@@ -1668,8 +1670,6 @@ class CMultiCoreJoinHelper: public CMultiCoreJoinHelperBase
     } **workers;
 
 public:
-    IMPLEMENT_IINTERFACE_USING(CSimpleInterface);
-
     CMultiCoreJoinHelper(CActivityBase &activity, unsigned numthreads, bool selfJoin, IJoinHelper *_jhelper, IHThorJoinArg *_helper, IRowInterfaces *_rowIf)
         : CMultiCoreJoinHelperBase(activity, numthreads, selfJoin, _jhelper, _helper, _rowIf)
     {
@@ -1866,8 +1866,6 @@ class CMultiCoreUnorderedJoinHelper: public CMultiCoreJoinHelperBase
     } **workers;
 
 public:
-    IMPLEMENT_IINTERFACE_USING(CSimpleInterface);
-
     CMultiCoreUnorderedJoinHelper(CActivityBase &activity, unsigned numthreads, bool selfJoin, IJoinHelper *_jhelper, IHThorJoinArg *_helper, IRowInterfaces *_rowIf)
         : CMultiCoreJoinHelperBase(activity, numthreads, selfJoin, _jhelper, _helper, _rowIf)
     {

+ 20 - 29
thorlcr/thorutil/thmem.cpp

@@ -625,13 +625,24 @@ void CThorExpandingRowArray::transferRows(rowidx_t & outNumRows, const void * *
     stableTable = NULL;
 }
 
-void CThorExpandingRowArray::transferRowsCopy(rowidx_t &outNumRows, const void **outRows)
+void CThorExpandingRowArray::transferRowsCopy(const void **outRows, bool takeOwnership)
 {
-    outNumRows = numRows;
+    if (0 == numRows)
+        return;
     memcpy(outRows, rows, numRows*sizeof(void **));
-    memset(rows, 0, numRows*sizeof(void **));
-    numRows = 0;
-    maxRows = 0;
+    if (takeOwnership)
+        numRows = 0;
+    else
+    {
+        const void **lastNewRow = outRows+numRows-1;
+        loop
+        {
+            LinkThorRow(*outRows);
+            if (outRows == lastNewRow)
+                break;
+            outRows++;
+        }
+    }
 }
 
 void CThorExpandingRowArray::transferFrom(CThorExpandingRowArray &donor)
@@ -674,19 +685,9 @@ bool CThorExpandingRowArray::appendRows(CThorExpandingRowArray &inRows, bool tak
         if (!ensure(numRows + num))
             return false;
     }
-    const void **_inRows = inRows.getRowArray();
     const void **newRows = rows+numRows;
-    inRows.transferRowsCopy(num, newRows);
-    if (!takeOwnership)
-    {
-        const void **lastNewRow = newRows+num-1;
-        do
-        {
-            LinkThorRow(*newRows);
-            newRows++;
-        }
-        while (newRows != lastNewRow);
-    }
+    inRows.transferRowsCopy(newRows, takeOwnership);
+
     numRows += num;
     return true;
 }
@@ -1171,19 +1172,9 @@ bool CThorSpillableRowArray::appendRows(CThorExpandingRowArray &inRows, bool tak
                 return false;
         }
     }
-    const void **_inRows = inRows.getRowArray();
     const void **newRows = rows+numRows;
-    inRows.transferRowsCopy(num, newRows);
-    if (!takeOwnership)
-    {
-        const void **lastNewRow = newRows+num-1;
-        do
-        {
-            LinkThorRow(*newRows);
-            newRows++;
-        }
-        while (newRows != lastNewRow);
-    }
+    inRows.transferRowsCopy(newRows, takeOwnership);
+
     numRows += num;
     if (numRows >= commitRows + commitDelta)
         flush();

+ 6 - 1
thorlcr/thorutil/thmem.hpp

@@ -249,6 +249,10 @@ class graph_decl CThorExpandingRowArray : public CSimpleInterface
         virtual void unlock() const {  }
     } dummyLock;
 
+
+// for direct access by another CThorExpandingRowArray only
+    inline void transferRowsCopy(const void **outRows, bool takeOwnership);
+
 protected:
     CActivityBase &activity;
     IRowInterfaces *rowIf;
@@ -341,7 +345,6 @@ public:
         swap(from);
     }
     void transferRows(rowidx_t & outNumRows, const void * * & outRows);
-    void transferRowsCopy(rowidx_t & outNumRows, const void **outRows);
     void transferFrom(CThorExpandingRowArray &src);
     void transferFrom(CThorSpillableRowArray &src);
     void removeRows(rowidx_t start, rowidx_t n);
@@ -367,6 +370,8 @@ public:
     void deserializeExpand(size32_t sz, const void *data);
     bool ensure(rowidx_t requiredRows);
     virtual IThorArrayLock &queryLock() { return dummyLock; }
+
+friend class CThorSpillableRowArray;
 };
 
 interface IWritePosCallback : extends IInterface