Skip to content

Commit

Permalink
No need for indirection of ImageEntry vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfpld committed Dec 12, 2023
1 parent 5decb91 commit cc3cbfe
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions public/client/TracyCallstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,14 @@ class ImageCache
};

ImageCache()
: m_images( 512 )
{
m_images = (FastVector<ImageEntry>*)tracy_malloc( sizeof( FastVector<ImageEntry> ) );
new(m_images) FastVector<ImageEntry>( 512 );

Refresh();
}

~ImageCache()
{
Clear();

m_images->~FastVector<ImageEntry>();
tracy_free( m_images );
}

const ImageEntry* GetImageForAddress( void* address )
Expand All @@ -139,7 +134,7 @@ class ImageCache
}

private:
tracy::FastVector<ImageEntry>* m_images;
tracy::FastVector<ImageEntry> m_images;
bool m_updated;

static int Callback( struct dl_phdr_info* info, size_t size, void* data )
Expand All @@ -154,7 +149,7 @@ class ImageCache
const auto endAddress = reinterpret_cast<void*>( info->dlpi_addr +
info->dlpi_phdr[info->dlpi_phnum - 1].p_vaddr + info->dlpi_phdr[info->dlpi_phnum - 1].p_memsz);

ImageEntry* image = cache->m_images->push_next();
ImageEntry* image = cache->m_images.push_next();
image->m_startAddress = startAddress;
image->m_endAddress = endAddress;

Expand Down Expand Up @@ -191,7 +186,7 @@ class ImageCache

bool Contains( void* startAddress ) const
{
return std::any_of( m_images->begin(), m_images->end(), [startAddress]( const ImageEntry& entry ) { return startAddress == entry.m_startAddress; } );
return std::any_of( m_images.begin(), m_images.end(), [startAddress]( const ImageEntry& entry ) { return startAddress == entry.m_startAddress; } );
}

void Refresh()
Expand All @@ -201,17 +196,17 @@ class ImageCache

if( m_updated )
{
std::sort( m_images->begin(), m_images->end(),
std::sort( m_images.begin(), m_images.end(),
[]( const ImageEntry& lhs, const ImageEntry& rhs ) { return lhs.m_startAddress > rhs.m_startAddress; } );
}
}

const ImageEntry* GetImageForAddressImpl( void* address ) const
{
auto it = std::lower_bound( m_images->begin(), m_images->end(), address,
auto it = std::lower_bound( m_images.begin(), m_images.end(), address,
[]( const ImageEntry& lhs, const void* rhs ) { return lhs.m_startAddress > rhs; } );

if( it != m_images->end() && address < it->m_endAddress )
if( it != m_images.end() && address < it->m_endAddress )
{
return it;
}
Expand All @@ -220,12 +215,12 @@ class ImageCache

void Clear()
{
for( ImageEntry& entry : *m_images )
for( ImageEntry& entry : m_images )
{
tracy_free( entry.m_name );
}

m_images->clear();
m_images.clear();
}
};
#endif //#ifdef TRACY_USE_IMAGE_CACHE
Expand Down

0 comments on commit cc3cbfe

Please sign in to comment.