Browse Source

minor cosmetic and ResetSchemaHelper

Dedicated reset need to eliminate warning about overriding non-virtual
function member.
Alexey N. Vinogradov 5 years ago
parent
commit
413b52feaa
7 changed files with 50 additions and 55 deletions
  1. 17 18
      src/docstore.cpp
  2. 3 6
      src/global_idf.cpp
  3. 1 1
      src/searchdhttp.cpp
  4. 11 12
      src/sphinx.cpp
  5. 11 11
      src/sphinx.h
  6. 2 2
      src/sphinxexpr.cpp
  7. 5 5
      src/sphinxjsonquery.cpp

+ 17 - 18
src/docstore.cpp

@@ -244,7 +244,7 @@ void DocstoreFields_c::Load ( CSphReader & tReader )
 	DWORD uNumFields = tReader.GetDword();
 	for ( int i = 0; i < (int)uNumFields; i++ )
 	{	
-		DocstoreDataType_e eType = (DocstoreDataType_e)tReader.GetByte();
+		auto eType = (DocstoreDataType_e)tReader.GetByte();
 		CSphString sName = tReader.GetString();
 		AddField ( sName, eType );
 	}
@@ -254,7 +254,7 @@ void DocstoreFields_c::Load ( CSphReader & tReader )
 void DocstoreFields_c::Save ( CSphWriter & tWriter )
 {
 	tWriter.PutDword ( GetNumFields() );
-	for ( int i = 0; i < GetNumFields(); i++ )
+	for ( int i = 0, iNumFields = GetNumFields(); i < iNumFields; ++i )
 	{
 		tWriter.PutByte ( GetField(i).m_eType );
 		tWriter.PutString ( GetField(i).m_sName );
@@ -599,8 +599,8 @@ DWORD DocstoreReaders_c::HashKey_t::Hash ( const HashKey_t & tKey )
 
 DocstoreReaders_c::~DocstoreReaders_c()
 {
-	for ( m_tHash.IterateStart(); m_tHash.IterateNext(); )
-		SafeDelete ( m_tHash.IterateGet() );
+	for ( auto & tDocstore : m_tHash )
+		SafeDelete ( tDocstore.second );
 }
 
 
@@ -653,9 +653,9 @@ void DocstoreReaders_c::DeleteBySessionId ( int64_t iSessionId )
 
 	// fixme: create a separate (faster) lookup?
 	CSphVector<std::pair<CSphReader*,HashKey_t>> dToDelete;
-	for ( m_tHash.IterateStart(); m_tHash.IterateNext(); )
-		if ( m_tHash.IterateGetKey().m_iSessionId==iSessionId )
-			dToDelete.Add ( {m_tHash.IterateGet(), m_tHash.IterateGetKey()} );
+	for ( auto & tDocstore : m_tHash )
+		if ( tDocstore.first.m_iSessionId==iSessionId )
+			dToDelete.Add ( { tDocstore.second, tDocstore.first } );
 
 	for ( const auto & i : dToDelete )
 		Delete ( i.first, i.second );
@@ -668,9 +668,9 @@ void DocstoreReaders_c::DeleteByDocstoreId ( DWORD uDocstoreId )
 
 	// fixme: create a separate (faster) lookup?
 	CSphVector<std::pair<CSphReader*,HashKey_t>> dToDelete;
-	for ( m_tHash.IterateStart(); m_tHash.IterateNext(); )
-		if ( m_tHash.IterateGetKey().m_uDocstoreId==uDocstoreId )
-			dToDelete.Add ( {m_tHash.IterateGet(), m_tHash.IterateGetKey()} );
+	for ( auto& tDocstore : m_tHash )
+		if ( tDocstore.first.m_uDocstoreId==uDocstoreId )
+			dToDelete.Add ( { tDocstore.second, tDocstore.first } );
 
 	for ( const auto & i : dToDelete )
 		Delete ( i.first, i.second );
@@ -699,16 +699,15 @@ DocstoreReaders_c * DocstoreReaders_c::Get()
 
 static void CreateFieldRemap ( VecTraits_T<int> & dFieldInRset, const VecTraits_T<int> * pFieldIds )
 {
-	ARRAY_FOREACH ( i, dFieldInRset )
-	{
-		if ( !pFieldIds )
-			dFieldInRset[i] = i;
-		else
+	if ( pFieldIds )
+		ARRAY_CONSTFOREACH ( i, dFieldInRset )
 		{
 			int * pFound = pFieldIds->BinarySearch(i);
-			dFieldInRset[i] = pFound ? (pFound-pFieldIds->Begin()) : -1;
+			dFieldInRset[i] = pFound ? pFieldIds->Idx ( pFound ) : -1;
 		}
-	}
+	else
+		ARRAY_CONSTFOREACH ( i, dFieldInRset )
+			dFieldInRset[i] = i;
 }
 
 
@@ -888,7 +887,7 @@ DocstoreDoc_t Docstore_c::GetDoc ( RowID_t tRowID, const VecTraits_T<int> * pFie
 {
 #ifndef NDEBUG
 	// assume that field ids are sorted
-	for ( int i = 1; pFieldIds && i < pFieldIds->GetLength(); i++ )
+	for ( int i = 1; pFieldIds && i < pFieldIds->GetLength(); ++i )
 		assert ( (*pFieldIds)[i-1] < (*pFieldIds)[i] );
 #endif
 

+ 3 - 6
src/global_idf.cpp

@@ -255,12 +255,9 @@ static StrVec_t CollectUnlistedIn ( const StrVec_t& dFiles ) REQUIRES ( !g_tGlob
 {
 	StrVec_t dCollection;
 	ScRL_t rLock ( g_tGlobalIDFLock );
-	for ( g_hGlobalIDFs.IterateStart (); g_hGlobalIDFs.IterateNext (); )
-	{
-		const CSphString& sKey = g_hGlobalIDFs.IterateGetKey ();
-		if ( !dFiles.Contains ( sKey ))
-			dCollection.Add ( sKey );
-	}
+	for ( auto& dIdf : g_hGlobalIDFs )
+		if ( !dFiles.Contains ( dIdf.first ) )
+			dCollection.Add ( dIdf.first );
 	return dCollection;
 }
 

+ 1 - 1
src/searchdhttp.cpp

@@ -524,7 +524,7 @@ public:
 		, HttpOptionsTraits_c ( tOptions )
 	{}
 
-	virtual bool Process () override
+	bool Process () final
 	{
 		CSphQuery tQuery;
 		CSphString sWarning;

+ 11 - 12
src/sphinx.cpp

@@ -6204,7 +6204,7 @@ void CSphSchemaHelper::Swap ( CSphSchemaHelper & rhs ) noexcept
 	rhs.m_dDynamicUsed.SwapData ( m_dDynamicUsed );
 }
 
-void CSphSchemaHelper::Reset()
+void CSphSchemaHelper::ResetSchemaHelper()
 {
 	m_dDataPtrAttrs.Reset();
 	m_dDynamicUsed.Reset ();
@@ -6504,7 +6504,7 @@ const CSphColumnInfo * CSphSchema::GetAttr ( const char * sName ) const
 
 void CSphSchema::Reset ()
 {
-	CSphSchemaHelper::Reset();
+	CSphSchemaHelper::ResetSchemaHelper();
 
 	m_dFields.Reset();
 	m_dAttrs.Reset();
@@ -6556,7 +6556,7 @@ void CSphSchema::RemoveAttr ( const char * szAttr, bool bDynamic )
 	else
 		m_dStaticUsed.Reset();
 
-	CSphSchemaHelper::Reset();
+	CSphSchemaHelper::ResetSchemaHelper();
 	m_dAttrs.Reset();
 	m_iFirstFieldLenAttr = -1;
 	m_iLastFieldLenAttr = -1;
@@ -6739,9 +6739,9 @@ bool CSphSchema::IsFieldStored ( int iField ) const
 
 //////////////////////////////////////////////////////////////////////////
 
-void CSphRsetSchema::Reset ()
+void CSphRsetSchema::ResetRsetSchema ()
 {
-	CSphSchemaHelper::Reset();
+	CSphSchemaHelper::ResetSchemaHelper();
 
 	m_pIndexSchema = nullptr;
 	m_dExtraAttrs.Reset();
@@ -6888,7 +6888,7 @@ CSphRsetSchema & CSphRsetSchema::operator = ( const ISphSchema & rhs )
 
 CSphRsetSchema & CSphRsetSchema::operator = ( const CSphSchema & rhs )
 {
-	Reset();
+	ResetRsetSchema();
 	m_pIndexSchema = &rhs;
 
 	// copy over dynamic rowitems map
@@ -14293,7 +14293,7 @@ void CSphQueryContext::BindWeights ( const CSphQuery * pQuery, const CSphSchema
 
 	// defaults
 	m_iWeights = Min ( tSchema.GetFieldsCount(), HEAVY_FIELDS );
-	for ( int i=0; i<m_iWeights; i++ )
+	for ( int i=0; i<m_iWeights; ++i )
 		m_dWeights[i] = 1;
 
 	// name-bound weights
@@ -14331,9 +14331,8 @@ void CSphQueryContext::BindWeights ( const CSphQuery * pQuery, const CSphSchema
 
 static ESphEvalStage GetEarliestStage ( ESphEvalStage eStage, const CSphColumnInfo & tIn, const CSphVector<const ISphSchema *> & dSchemas )
 {
-	ARRAY_FOREACH ( iSchema, dSchemas )
+	for ( const auto * pSchema : dSchemas )
 	{
-		const ISphSchema * pSchema = dSchemas[iSchema];
 		const CSphColumnInfo * pCol = pSchema->GetAttr ( tIn.m_sName.cstr() );
 		if ( !pCol )
 			continue;
@@ -15920,7 +15919,7 @@ bool CSphIndex_VLN::MultiQueryEx ( int iQueries, const CSphQuery * pQueries,
 
 		CSphQueryNodeCache tNodeCache ( iCommonSubtrees, m_iMaxCachedDocs, m_iMaxCachedHits );
 		bResult = false;
-		for ( int j=0; j<iQueries; j++ )
+		for ( int j=0; j<iQueries; ++j )
 		{
 			// fullscan case
 			if ( pQueries[j].m_sQuery.IsEmpty() )
@@ -22238,7 +22237,7 @@ bool CSphSource_Document::IterateDocument ( bool & bEOF, CSphString & sError )
 		break;
 	}
 
-	m_tStats.m_iTotalDocuments++;
+	++m_tStats.m_iTotalDocuments;
 	return true;
 }
 
@@ -23271,7 +23270,7 @@ bool CSphSource_SQL::IterateStart ( CSphString & sError )
 	// some post-query setup
 	m_tSchema.Reset();
 
-	for ( int i=0; i<SPH_MAX_FIELDS; i++ )
+	for ( int i=0; i<SPH_MAX_FIELDS; ++i )
 		m_dUnpack[i] = SPH_UNPACK_NONE;
 
 	m_iSqlFields = SqlNumFields(); // for rowdump

+ 11 - 11
src/sphinx.h

@@ -57,10 +57,12 @@
 /////////////////////////////////////////////////////////////////////////////
 
 using RowID_t = DWORD;
+const RowID_t INVALID_ROWID = 0xFFFFFFFF;
+
 using DocID_t = int64_t;
+#define DOCID_MIN        (INT64_MIN)
 
-const RowID_t INVALID_ROWID = 0xFFFFFFFF;
-#define WORDID_MAX		U64C(0xffffffffffffffff)
+#define WORDID_MAX        U64C(0xffffffffffffffff)
 
 STATIC_SIZE_ASSERT ( DocID_t, 8 );
 STATIC_SIZE_ASSERT ( RowID_t, 4 );
@@ -1099,7 +1101,7 @@ inline void sphAddCounterScalar ( CSphRowitem * pRow, const CSphAttrLocator & tL
 
 
 /// search query match (document info plus weight/tag)
-class CSphMatch
+class CSphMatch : public ISphNoncopyable
 {
 	friend class ISphSchema;
 	friend class CSphSchema;
@@ -1243,15 +1245,14 @@ public:
 	/// fetches blobs from both data ptr attrs and pooled blob attrs
 	const BYTE * FetchAttrData ( const CSphAttrLocator & tLoc, const BYTE * pPool, int & iLengthBytes ) const;
 	ByteBlob_t FetchAttrData ( const CSphAttrLocator & tLoc, const BYTE * pPool ) const;
-
-	/// "manually" prevent copying
-	CSphMatch & operator = ( const CSphMatch & ) = delete;
-	CSphMatch ( const CSphMatch &) = delete;
 };
 
 /// specialized swapper
 inline void Swap ( CSphMatch & a, CSphMatch & b )
 {
+	if ( &a==&b )
+		return;
+
 	Swap ( a.m_tRowID, b.m_tRowID );
 	Swap ( a.m_pStatic, b.m_pStatic );
 	Swap ( a.m_pDynamic, b.m_pDynamic );
@@ -1443,7 +1444,7 @@ protected:
 
 	/// generic InsertAttr() implementation that tracks data ptr attributes
 	void			InsertAttr ( CSphVector<CSphColumnInfo> & dAttrs, CSphVector<int> & dUsed, int iPos, const CSphColumnInfo & tCol, bool bDynamic );
-	void			Reset();
+	void			ResetSchemaHelper();
 
 	void CopyPtrs ( CSphMatch & tDst, const CSphMatch & rhs ) const;
 
@@ -1628,7 +1629,7 @@ public:
 
 public:
 	void				RemoveStaticAttr ( int iAttr );
-	void				Reset();
+	void				ResetRsetSchema();
 
 public:
 	/// swap in a subset of current attributes, with not necessarily (!) unique names
@@ -2981,7 +2982,6 @@ public:
 
 	/// store all entries into specified location and remove them from the queue
 	/// entries are stored in properly sorted order,
-	/// if iTag is non-negative, entries are also tagged; otherwise, their tag's unchanged
 	/// return sorted entries count, might be less than length due of aggregate filtering phase
 	virtual int			Flatten ( CSphMatch * pTo, int iTag ) = 0;
 
@@ -3485,7 +3485,7 @@ ESortClauseParseResult	sphParseSortClause ( const CSphQuery * pQuery, const char
 /// if the pUpdate is given, creates the updater's queue and perform the index update
 /// instead of searching
 ISphMatchSorter *	sphCreateQueue ( const SphQueueSettings_t & tQueue, const CSphQuery & tQuery,
-		CSphString & sError, SphQueueRes_t & tRes, StrVec_t * pExtra );
+		CSphString & sError, SphQueueRes_t & tRes, StrVec_t * pExtra = nullptr );
 
 void sphCreateMultiQueue ( const SphQueueSettings_t & tQueue, const VecTraits_T<CSphQuery> & dQueries,
 		VecTraits_T<ISphMatchSorter *> & dSorters, VecTraits_T<CSphString> & dErrors, SphQueueRes_t & tRes,

+ 2 - 2
src/sphinxexpr.cpp

@@ -392,8 +392,8 @@ private:
 class Expr_GetField_c : public Expr_NoLocator_c
 {
 public:
-	explicit Expr_GetField_c ( const CSphString & sField )
-		: m_sField ( sField )
+	explicit Expr_GetField_c ( CSphString sField )
+		: m_sField ( std::move (sField ) )
 	{}
 
 	float	Eval ( const CSphMatch & ) const final { assert(0); return 0; }

+ 5 - 5
src/sphinxjsonquery.cpp

@@ -1162,7 +1162,7 @@ static void JsonObjAddAttr ( JsonEscapedBuilder & tOut, const AggrResult_t &tRes
 	case SPH_ATTR_INT64SET_PTR:
 	{
 		tOut.ArrayBlock ();
-		const BYTE * pMVA = ( const BYTE * ) tMatch.GetAttr ( tLoc );
+		const auto * pMVA = ( const BYTE * ) tMatch.GetAttr ( tLoc );
 		if ( eAttrType==SPH_ATTR_UINT32SET_PTR )
 			PackedShortMVA2Json ( tOut, pMVA );
 		else
@@ -1204,7 +1204,7 @@ static void JsonObjAddAttr ( JsonEscapedBuilder & tOut, const AggrResult_t &tRes
 
 	case SPH_ATTR_JSON_PTR:
 	{
-		const BYTE * pJSON = ( const BYTE * ) tMatch.GetAttr ( tLoc );
+		const auto * pJSON = ( const BYTE * ) tMatch.GetAttr ( tLoc );
 		sphUnpackPtrAttr ( pJSON, &pJSON );
 
 		// no object at all? return NULL
@@ -1220,7 +1220,7 @@ static void JsonObjAddAttr ( JsonEscapedBuilder & tOut, const AggrResult_t &tRes
 	case SPH_ATTR_FACTORS:
 	case SPH_ATTR_FACTORS_JSON:
 	{
-		const BYTE * pFactors = ( const BYTE * ) tMatch.GetAttr ( tLoc );
+		const auto * pFactors = ( const BYTE * ) tMatch.GetAttr ( tLoc );
 		sphUnpackPtrAttr ( pFactors, &pFactors );
 		if ( pFactors )
 			sphFormatFactors ( tOut, ( const unsigned int * ) pFactors, true );
@@ -1231,7 +1231,7 @@ static void JsonObjAddAttr ( JsonEscapedBuilder & tOut, const AggrResult_t &tRes
 
 	case SPH_ATTR_JSON_FIELD_PTR:
 	{
-		const BYTE * pField = ( const BYTE * ) tMatch.GetAttr ( tLoc );
+		const auto * pField = ( const BYTE * ) tMatch.GetAttr ( tLoc );
 		sphUnpackPtrAttr ( pField, &pField );
 		if ( !pField )
 		{
@@ -1304,7 +1304,7 @@ void EncodeHighlight ( const CSphMatch & tMatch, int iAttr, const ISphSchema & t
 	const CSphColumnInfo & tCol = tSchema.GetAttr(iAttr);
 
 	ScopedComma_c tHighlightComma ( tOut, ",", R"("highlight":{)", "}", false );
-	auto pData = (const BYTE *)tMatch.GetAttr ( tCol.m_tLocator );
+	const auto * pData = (const BYTE *)tMatch.GetAttr ( tCol.m_tLocator );
 	int iLength = sphUnpackPtrAttr ( pData, &pData );
 
 	SnippetResult_t tRes;