瀏覽代碼

simplify checkpoints codeflow

It is not necessary to make low-level things with pointers since
checkpoints are always accessible from vectors.
Alexey N. Vinogradov 4 年之前
父節點
當前提交
85dbc76fd6
共有 4 個文件被更改,包括 13 次插入17 次删除
  1. 2 2
      src/indexformat.cpp
  2. 7 9
      src/sphinxint.h
  3. 2 2
      src/sphinxpq.cpp
  4. 2 4
      src/sphinxrt.cpp

+ 2 - 2
src/indexformat.cpp

@@ -415,10 +415,10 @@ const CSphWordlistCheckpoint * CWordlist::FindCheckpoint ( const char * sWord, i
 	if ( m_pCpReader ) // FIXME!!! fall to regular checkpoints after data got read
 	{
 		MappedCheckpoint_fn tPred ( m_dCheckpoints.Begin(), m_tBuf.GetWritePtr() + m_iDictCheckpointsOffset, m_pCpReader );
-		return sphSearchCheckpoint ( sWord, iWordLen, iWordID, bStarMode, m_bWordDict, m_dCheckpoints.Begin(), &m_dCheckpoints.Last(), std::move(tPred) );
+		return sphSearchCheckpoint ( sWord, iWordLen, iWordID, bStarMode, m_bWordDict, m_dCheckpoints, std::move(tPred) );
 	}
 
-	return sphSearchCheckpoint ( sWord, iWordLen, iWordID, bStarMode, m_bWordDict, m_dCheckpoints.Begin(), &m_dCheckpoints.Last() );
+	return sphSearchCheckpoint ( sWord, iWordLen, iWordID, bStarMode, m_bWordDict, m_dCheckpoints );
 }
 
 

+ 7 - 9
src/sphinxint.h

@@ -1269,14 +1269,12 @@ int sphCheckpointCmpStrictly ( const char * sWord, int iLen, SphWordID_t iWordID
 }
 
 template < typename CP, typename PRED >
-const CP * sphSearchCheckpoint ( const char * sWord, int iWordLen, SphWordID_t iWordID
-							, bool bStarMode, bool bWordDict
-							, const CP * pFirstCP, const CP * pLastCP, PRED && tPred )
+const CP * sphSearchCheckpoint ( const char * sWord, int iWordLen, SphWordID_t iWordID, bool bStarMode, bool bWordDict, VecTraits_T<CP> dCheckpoints, PRED && tPred )
 {
 	assert ( !bWordDict || iWordLen>0 );
 
-	const CP * pStart = pFirstCP;
-	const CP * pEnd = pLastCP;
+	const CP * pStart = dCheckpoints.begin();
+	const CP * pEnd = &dCheckpoints.Last();
 
 	if ( bStarMode && sphCheckpointCmp ( sWord, iWordLen, iWordID, bWordDict, tPred ( pStart ) )<0 )
 		return nullptr;
@@ -1299,8 +1297,8 @@ const CP * sphSearchCheckpoint ( const char * sWord, int iWordLen, SphWordID_t i
 			pStart = pMid;
 	}
 
-	assert ( pStart >= pFirstCP );
-	assert ( pStart <= pLastCP );
+	assert ( pStart >= dCheckpoints.begin() );
+	assert ( pStart <= &dCheckpoints.Last() );
 	assert ( sphCheckpointCmp ( sWord, iWordLen, iWordID, bWordDict, tPred ( pStart ) )>=0
 		&& sphCheckpointCmpStrictly ( sWord, iWordLen, iWordID, bWordDict, tPred ( pEnd ) )<0 );
 
@@ -1308,9 +1306,9 @@ const CP * sphSearchCheckpoint ( const char * sWord, int iWordLen, SphWordID_t i
 }
 
 template < typename CP >
-const CP * sphSearchCheckpoint ( const char * sWord, int iWordLen, SphWordID_t iWordID, bool bStarMode, bool bWordDict , const CP * pFirstCP, const CP * pLastCP )
+const CP * sphSearchCheckpoint ( const char * sWord, int iWordLen, SphWordID_t iWordID, bool bStarMode, bool bWordDict, VecTraits_T<CP> dCheckpoints )
 {
-	return sphSearchCheckpoint ( sWord, iWordLen, iWordID, bStarMode, bWordDict, pFirstCP, pLastCP, [] ( const CP* pCP ) { return *pCP; } );
+	return sphSearchCheckpoint ( sWord, iWordLen, iWordID, bStarMode, bWordDict, std::move(dCheckpoints), [] ( const CP* pCP ) { return *pCP; } );
 }
 
 

+ 2 - 2
src/sphinxpq.cpp

@@ -514,7 +514,7 @@ static Slice_t GetTermLocator ( const char * sWord, int iLen, const RtSegment_t
 	// tighten dictionary location
 	if ( pSeg->m_dWordCheckpoints.GetLength() )
 	{
-		const RtWordCheckpoint_t * pCheckpoint = sphSearchCheckpoint ( sWord, iLen, 0, false, true, pSeg->m_dWordCheckpoints.Begin(), &pSeg->m_dWordCheckpoints.Last() );
+		const RtWordCheckpoint_t * pCheckpoint = sphSearchCheckpoint ( sWord, iLen, 0, false, true, pSeg->m_dWordCheckpoints );
 		if ( !pCheckpoint )
 		{
 			tChPoint.m_uLen = pSeg->m_dWordCheckpoints.Begin()->m_iOffset;
@@ -571,7 +571,7 @@ static Slice_t GetPrefixLocator ( const char * sWord, bool bHasMorphology, const
 	if ( !pSeg->m_dWordCheckpoints.IsEmpty() )
 	{
 		const RtWordCheckpoint_t * pLast = &pSeg->m_dWordCheckpoints.Last();
-		const RtWordCheckpoint_t * pCheckpoint = sphSearchCheckpoint ( sPrefix, iPrefix, 0, true, true, pSeg->m_dWordCheckpoints.Begin(), pLast );
+		const RtWordCheckpoint_t * pCheckpoint = sphSearchCheckpoint ( sPrefix, iPrefix, 0, true, true, pSeg->m_dWordCheckpoints );
 
 		if ( pCheckpoint )
 		{

+ 2 - 4
src/sphinxrt.cpp

@@ -5280,7 +5280,7 @@ bool RtIndex_c::RtQwordSetupSegment ( RtQword_t * pQword, const RtSegment_t * pC
 
 	if ( pCurSeg->m_dWordCheckpoints.GetLength() )
 	{
-		const RtWordCheckpoint_t * pCp = sphSearchCheckpoint ( sWord, iWordLen, uWordID, false, m_bKeywordDict, pCurSeg->m_dWordCheckpoints.Begin(), &pCurSeg->m_dWordCheckpoints.Last() );
+		const RtWordCheckpoint_t * pCp = sphSearchCheckpoint ( sWord, iWordLen, uWordID, false, m_bKeywordDict, pCurSeg->m_dWordCheckpoints );
 
 		const BYTE * pWords = pCurSeg->m_dWords.Begin();
 
@@ -5558,9 +5558,7 @@ void RtIndex_c::GetPrefixedWords ( const char * sSubstring, int iSubLen, const c
 		// find initial checkpoint or check words prior to 1st checkpoint
 		if ( pCurSeg->m_dWordCheckpoints.GetLength() )
 		{
-			const RtWordCheckpoint_t * pCurCheckpoint = sphSearchCheckpoint ( sSubstring, iSubLen, 0, true, true
-				, pCurSeg->m_dWordCheckpoints.Begin(), &pCurSeg->m_dWordCheckpoints.Last() );
-
+			const RtWordCheckpoint_t * pCurCheckpoint = sphSearchCheckpoint ( sSubstring, iSubLen, 0, true, true, pCurSeg->m_dWordCheckpoints );
 			if ( pCurCheckpoint )
 			{
 				// there could be valid data prior 1st checkpoint that should be unpacked and checked