Skip to content

Commit

Permalink
minors
Browse files Browse the repository at this point in the history
  • Loading branch information
klirichek committed Dec 17, 2024
1 parent eae8692 commit fd3cfa4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/querycontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static FORCE_INLINE void FreeDataPtrAttrs ( CSphMatch & tMatch, const CSphVector
{
const auto & tItem = dItems[i];

BYTE * pData = (BYTE *)tMatch.GetAttr ( tItem.m_tLoc );
auto * pData = (BYTE *)tMatch.GetAttr ( tItem.m_tLoc );
// delete[] pData;
if ( pData )
{
Expand Down
4 changes: 2 additions & 2 deletions src/schema/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void CSphSchemaHelper::ResetSchemaHelper()

void CSphSchemaHelper::CloneMatch ( CSphMatch& tDst, const CSphMatch& rhs ) const
{
if ( m_dDataPtrAttrs.GetLength() )
if ( !m_dDataPtrAttrs.IsEmpty() )
CloneMatchSpecial ( tDst, rhs, m_dDataPtrAttrs );
else
tDst.Combine ( rhs, GetDynamicSize() );
Expand Down Expand Up @@ -134,7 +134,7 @@ CSphVector<int> CSphSchemaHelper::SubsetPtrs ( CSphVector<int>& dDiscarded ) con
}

// declared in sphinxstd.h
void sphDeallocatePacked ( BYTE* pBlob )
void sphDeallocatePacked ( const BYTE* pBlob )
{
if ( !pBlob )
return;
Expand Down
46 changes: 27 additions & 19 deletions src/schema/locator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@
#include <cstdint>
#include "sphinxdefs.h"


struct SmallAttrLocator_t
{
int m_iBitOffset = -1;
int m_iBitCount = -1;

SmallAttrLocator_t () = default;
explicit SmallAttrLocator_t ( int iBitOffset, int iBitCount = ROWITEM_BITS );

inline bool IsBitfield () const noexcept;

int CalcRowitem () const noexcept;

#ifndef NDEBUG

/// get last item touched by this attr (for debugging checks only)
int GetMaxRowitem () const noexcept;

#endif
};

/// attribute locator within the row
struct CSphAttrLocator
struct CSphAttrLocator : public SmallAttrLocator_t
{
int m_iBitOffset = -1;
int m_iBitCount = -1;
int m_iBlobAttrId = -1;
int m_iBlobRowOffset = 1;
int m_nBlobAttrs = 0;
Expand All @@ -29,35 +48,24 @@ struct CSphAttrLocator

CSphAttrLocator () = default;

explicit CSphAttrLocator ( int iBitOffset, int iBitCount=ROWITEM_BITS );

inline bool IsBitfield () const;

int CalcRowitem () const;

bool IsBlobAttr() const;
bool IsBlobAttr() const noexcept;

void Reset();

// just sphFNV64 (&loc,sizeof(loc)) isn't correct as members are not aligned
uint64_t FNV ( uint64_t uHash ) const;

#ifndef NDEBUG
/// get last item touched by this attr (for debugging checks only)
int GetMaxRowitem () const;
#endif

bool operator == ( const CSphAttrLocator & rhs ) const;
};

SphAttr_t sphGetRowAttr ( const CSphRowitem* pRow, const CSphAttrLocator& tLoc );
SphAttr_t sphGetRowAttr ( const CSphRowitem* pRow, SmallAttrLocator_t tLoc );

void sphSetRowAttr ( CSphRowitem* pRow, const CSphAttrLocator& tLoc, SphAttr_t uValue );
void sphSetRowAttr ( CSphRowitem* pRow, SmallAttrLocator_t tLoc, SphAttr_t uValue );

/// add numeric value of another attribute
void sphAddCounterAttr ( CSphRowitem* pRow, const CSphRowitem* pVal, const CSphAttrLocator& tLoc );
void sphAddCounterAttr ( CSphRowitem* pRow, const CSphRowitem* pVal, SmallAttrLocator_t tLoc );

/// add scalar value to aligned numeric attribute
void sphAddCounterScalar ( CSphRowitem* pRow, const CSphAttrLocator& tLoc, SphAttr_t uValue );
void sphAddCounterScalar ( CSphRowitem* pRow, SmallAttrLocator_t tLoc, SphAttr_t uValue );

#include "locator_impl.h"
18 changes: 9 additions & 9 deletions src/schema/locator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@

#include "std/fnv64.h"

inline CSphAttrLocator::CSphAttrLocator ( int iBitOffset, int iBitCount )
inline SmallAttrLocator_t::SmallAttrLocator_t ( int iBitOffset, int iBitCount )
: m_iBitOffset ( iBitOffset )
, m_iBitCount ( iBitCount )
{}

inline bool CSphAttrLocator::IsBitfield() const
inline bool SmallAttrLocator_t::IsBitfield() const noexcept
{
return ( m_iBitCount < ROWITEM_BITS || ( m_iBitOffset % ROWITEM_BITS ) != 0 );
}

inline int CSphAttrLocator::CalcRowitem() const
inline int SmallAttrLocator_t::CalcRowitem() const noexcept
{
return IsBitfield() ? -1 : ( m_iBitOffset / ROWITEM_BITS );
}

inline bool CSphAttrLocator::IsBlobAttr() const
inline bool CSphAttrLocator::IsBlobAttr() const noexcept
{
return m_iBlobAttrId >= 0;
}
Expand Down Expand Up @@ -68,7 +68,7 @@ inline uint64_t CSphAttrLocator::FNV ( uint64_t uHash ) const

#ifndef NDEBUG
/// get last item touched by this attr (for debugging checks only)
inline int CSphAttrLocator::GetMaxRowitem() const
inline int SmallAttrLocator_t::GetMaxRowitem() const noexcept
{
return ( m_iBitOffset + m_iBitCount - 1 ) / ROWITEM_BITS;
}
Expand All @@ -82,7 +82,7 @@ inline bool CSphAttrLocator::operator== ( const CSphAttrLocator& rhs ) const
return m_bDynamic == rhs.m_bDynamic && m_iBlobAttrId == rhs.m_iBlobAttrId && m_nBlobAttrs == rhs.m_nBlobAttrs;
}

FORCE_INLINE SphAttr_t sphGetRowAttr ( const CSphRowitem * pRow, const CSphAttrLocator & tLoc )
FORCE_INLINE SphAttr_t sphGetRowAttr ( const CSphRowitem * pRow, SmallAttrLocator_t tLoc )
{
assert(pRow);
assert ( tLoc.m_iBitCount );
Expand All @@ -106,7 +106,7 @@ FORCE_INLINE SphAttr_t sphGetRowAttr ( const CSphRowitem * pRow, const CSphAttrL
}


FORCE_INLINE void sphSetRowAttr ( CSphRowitem * pRow, const CSphAttrLocator & tLoc, SphAttr_t uValue )
FORCE_INLINE void sphSetRowAttr ( CSphRowitem * pRow, SmallAttrLocator_t tLoc, SphAttr_t uValue )
{
assert(pRow);
assert ( tLoc.m_iBitCount );
Expand Down Expand Up @@ -135,7 +135,7 @@ FORCE_INLINE void sphSetRowAttr ( CSphRowitem * pRow, const CSphAttrLocator & tL
}

/// add numeric value of another attribute
inline void sphAddCounterAttr ( CSphRowitem * pRow, const CSphRowitem * pVal, const CSphAttrLocator & tLoc )
inline void sphAddCounterAttr ( CSphRowitem * pRow, const CSphRowitem * pVal, SmallAttrLocator_t tLoc )
{
assert( pRow && pVal);
int iItem = tLoc.m_iBitOffset >> ROWITEM_SHIFT;
Expand Down Expand Up @@ -164,7 +164,7 @@ inline void sphAddCounterAttr ( CSphRowitem * pRow, const CSphRowitem * pVal, co
}

/// add scalar value to aligned numeric attribute
inline void sphAddCounterScalar ( CSphRowitem * pRow, const CSphAttrLocator & tLoc, SphAttr_t uValue )
inline void sphAddCounterScalar ( CSphRowitem * pRow, SmallAttrLocator_t tLoc, SphAttr_t uValue )
{
assert( pRow );
int iItem = tLoc.m_iBitOffset >> ROWITEM_SHIFT;
Expand Down
2 changes: 1 addition & 1 deletion src/std/smalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ namespace sph {
template<typename T>
using TightPackedVec_T = sph::Vector_T<T, sph::DefaultCopy_T<T>, sph::TightRelimit, sph::CustomStorage_T<T>>;

void sphDeallocatePacked ( BYTE * pBlob );
void sphDeallocatePacked ( const BYTE * pBlob );

#include "smalloc_impl.h"
4 changes: 2 additions & 2 deletions src/std/vectraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class VecTraits_T
FORCE_INLINE T * End() const;

/// make happy C++11 ranged for loops
FORCE_INLINE T * begin() const;
FORCE_INLINE T * end() const;
FORCE_INLINE T * begin() const noexcept;
FORCE_INLINE T * end() const noexcept;

/// get first entry
T& First() const;
Expand Down
4 changes: 2 additions & 2 deletions src/std/vectraits_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ T* VecTraits_T<T>::End() const

/// make happy C++11 ranged for loops
template<typename T>
T* VecTraits_T<T>::begin() const
T* VecTraits_T<T>::begin() const noexcept
{
return Begin();
}

template<typename T>
T* VecTraits_T<T>::end() const
T* VecTraits_T<T>::end() const noexcept
{
return m_iCount ? m_pData + m_iCount : nullptr;
}
Expand Down

0 comments on commit fd3cfa4

Please sign in to comment.