Permalink
Browse files

Close #436 Introduce small obj allocator for ptr attrs

  • Loading branch information...
klirichek committed Sep 5, 2018
1 parent 25453e5 commit 204f521408b730198a5bab2c20407a3d7df94873
Showing with 489 additions and 11 deletions.
  1. +22 −5 src/sphinx.cpp
  2. +0 −1 src/sphinx.h
  3. +5 −5 src/sphinxsort.cpp
  4. +456 −0 src/sphinxstd.cpp
  5. +6 −0 src/sphinxstd.h
@@ -5851,7 +5851,8 @@ BYTE * sphPackPtrAttr ( const BYTE * pData, int iLengthBytes )
assert ( pData );
BYTE * pPacked = new BYTE [sphCalcPackedLength(iLengthBytes)];
//BYTE * pPacked = new BYTE [sphCalcPackedLength(iLengthBytes)];
BYTE * pPacked = sphAllocateSmall ( sphCalcPackedLength ( iLengthBytes ) );
sphPackPtrAttr ( pPacked, pData, iLengthBytes );
return pPacked;
}
@@ -5867,7 +5868,8 @@ void sphPackPtrAttr ( BYTE * pPrealloc, const BYTE * pData, int iLengthBytes )
BYTE * sphPackPtrAttr ( int iLengthBytes, BYTE * & pData )
{
BYTE * pPacked = new BYTE [sphCalcPackedLength(iLengthBytes)];
// BYTE * pPacked = new BYTE [sphCalcPackedLength(iLengthBytes)];
BYTE * pPacked = sphAllocateSmall ( sphCalcPackedLength ( iLengthBytes ) );
pData = pPacked;
pData += sphZipToPtr ( iLengthBytes, pPacked );
return pPacked;
@@ -6021,6 +6023,15 @@ void CSphSchemaHelper::CloneMatchSpecial ( CSphMatch * pDst, const CSphMatch &rh
CopyPtrsSpecial ( pDst, rhs.m_pDynamic, dSpecials );
}
// declared in sphinxstd.h
void sphDeallocatePacked ( BYTE * pBlob )
{
if ( !pBlob )
return;
const BYTE * pFoo = pBlob;
sphDeallocateSmall ( pBlob, sphCalcPackedLength ( sphUnzipInt ( pFoo ) ) );
}
void CSphSchemaHelper::FreeDataSpecial ( CSphMatch * pMatch, const CSphVector<int> &dSpecials )
{
assert ( pMatch );
@@ -6030,7 +6041,9 @@ void CSphSchemaHelper::FreeDataSpecial ( CSphMatch * pMatch, const CSphVector<in
for ( auto iOffset : dSpecials )
{
BYTE * &pData = *( BYTE ** ) ( pMatch->m_pDynamic + iOffset );
SafeDeleteArray ( pData );
// SafeDeleteArray ( pData );
sphDeallocatePacked ( pData );
pData = nullptr;
}
}
@@ -14594,8 +14607,12 @@ static inline void FreeDataPtrAttrs ( CSphMatch & tMatch, const CSphVector<CSphQ
if ( sphIsDataPtrAttr ( i.m_eType ) )
{
BYTE * pData = (BYTE *)tMatch.GetAttr ( i.m_tLoc );
delete [] pData;
tMatch.SetAttr ( i.m_tLoc, 0 );
// delete[] pData;
if ( pData )
{
sphDeallocatePacked ( pData );
tMatch.SetAttr ( i.m_tLoc, 0 );
}
}
}
@@ -3580,7 +3580,6 @@ volatile int& sphGetTFO();
#define TFO_LISTEN 2
#define TFO_ABSENT (-1)
/////////////////////////////////////////////////////////////////////////////
// workaround to suppress C4511/C4512 warnings (copy ctor and assignment operator) in VS 2003
#if _MSC_VER>=1300 && _MSC_VER<1400
#pragma warning(disable:4511)
@@ -1527,9 +1527,9 @@ class AggrConcat_t : public IAggrFunc
void Update ( CSphMatch * pDst, const CSphMatch * pSrc, bool ) override
{
const BYTE * sSrc = (const BYTE*)pSrc->GetAttr(m_tLoc);
const BYTE * sDst = (const BYTE*)pDst->GetAttr(m_tLoc);
const BYTE * pOldDst = sDst;
auto sSrc = (const BYTE*)pSrc->GetAttr(m_tLoc);
auto sDst = (const BYTE*)pDst->GetAttr(m_tLoc);
auto pOldDst = const_cast<BYTE*> ( sDst );
int iSrc = sphUnpackPtrAttr ( sSrc, &sSrc );
int iDst = sphUnpackPtrAttr ( sDst, &sDst );
@@ -1558,8 +1558,8 @@ class AggrConcat_t : public IAggrFunc
memcpy ( dNew.Begin()+iDst+1, sSrc, iSrc );
// clear dst to avoid leaks
SafeDeleteArray ( pOldDst );
// SafeDeleteArray ( pOldDst );
sphDeallocatePacked ( pOldDst );
pDst->SetAttr ( m_tLoc, (SphAttr_t)sphPackPtrAttr ( dNew.Begin(), iSrc+iDst+1 ) );
}
};
Oops, something went wrong.

0 comments on commit 204f521

Please sign in to comment.