Skip to content
This repository
Browse code

Image: Have block rasterize copy its cache handles

Trying to reudce the pointer overhead when talking to the cache.
  • Loading branch information...
commit f256ec20281e9b7944fe1b7891d9cfed0b840bb1 1 parent 1d327e1
Zack Moratto zmoratto authored

Showing 1 changed file with 14 additions and 8 deletions. Show diff stats Hide diff stats

  1. +14 8 src/vw/Image/BlockRasterize.h
22 src/vw/Image/BlockRasterize.h
@@ -65,8 +65,8 @@ namespace vw {
65 65 #endif
66 66 if ( m_cache_ptr ) {
67 67 // Early-out optimization for single-block resources
68   - if( m_block_table->size() == 1 ) {
69   - return ((*m_block_table)[0])->operator()( x, y, p );
  68 + if( m_block_table.size() == 1 ) {
  69 + return m_block_table[0]->operator()( x, y, p );
70 70 }
71 71 int32 ix = x/m_block_size.x(), iy = y/m_block_size.y();
72 72 return block(ix,iy)->operator()( x-ix*m_block_size.x(), y - iy*m_block_size.y(), p );
@@ -160,7 +160,7 @@ namespace vw {
160 160 if( m_cache_ptr ) {
161 161 m_table_width = (cols()-1) / m_block_size.x() + 1;
162 162 m_table_height = (rows()-1) / m_block_size.y() + 1;
163   - m_block_table.reset( new std::vector<Cache::Handle<BlockGenerator> >( m_table_width * m_table_height ) );
  163 + m_block_table.resize( m_table_width * m_table_height );
164 164 BBox2i view_bbox(0,0,cols(),rows());
165 165 for( int32 iy=0; iy<m_table_height; ++iy ) {
166 166 for( int32 ix=0; ix<m_table_width; ++ix ) {
@@ -172,11 +172,18 @@ namespace vw {
172 172 }
173 173 }
174 174
175   - Cache::Handle<BlockGenerator>& block( int ix, int iy ) const {
  175 + const Cache::Handle<BlockGenerator>& block( int ix, int iy ) const {
176 176 if( ix<0 || ix>=m_table_width || iy<0 || iy>=m_table_height )
177 177 vw_throw( ArgumentErr() << "BlockRasterizeView: Block indices out of bounds, (" << ix
178 178 << "," << iy << ") of (" << m_table_width << "," << m_table_height << ")" );
179   - return (*m_block_table)[ix+iy*m_table_width];
  179 + return m_block_table[ix+iy*m_table_width];
  180 + }
  181 +
  182 + Cache::Handle<BlockGenerator>& block( int ix, int iy ) {
  183 + if( ix<0 || ix>=m_table_width || iy<0 || iy>=m_table_height )
  184 + vw_throw( ArgumentErr() << "BlockRasterizeView: Block indices out of bounds, (" << ix
  185 + << "," << iy << ") of (" << m_table_width << "," << m_table_height << ")" );
  186 + return m_block_table[ix+iy*m_table_width];
180 187 }
181 188
182 189 // We store this by shared pointer so it doesn't move when we copy
@@ -186,9 +193,8 @@ namespace vw {
186 193 int32 m_num_threads;
187 194 Cache *m_cache_ptr;
188 195 int m_table_width, m_table_height;
189   - // We store this by shared pointer so copying a BlockRasterizeView
190   - // (i.e. to promote its scope) is not as expensive an operation.
191   - boost::shared_ptr<std::vector<Cache::Handle<BlockGenerator> > > m_block_table;
  196 + // Handles are lightweight and are just pointers underneath
  197 + std::vector<Cache::Handle<BlockGenerator> > m_block_table;
192 198 };
193 199
194 200 template <class ImageT>

0 comments on commit f256ec2

Please sign in to comment.
Something went wrong with that request. Please try again.