Changeset 3304

Show
Ignore:
Timestamp:
11/06/09 22:34:51 (2 weeks ago)
Author:
kraftche
Message:

Move special case for 1 input entity in vector-vector get_adjaciences to
common intersect implementation:

o moves conditional statement outside of loop, reducing skinning time

a little bit (6.86s vs 7.01s).

o avoids doing swap on input vector, which might avoid additional memory

allocations for many vector-vector calls in a loop

o all versions of get_adjacencies with op==intersect benefit from the

optimization, rather than just the vector-vector one.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • MOAB/trunk/MBCore.cpp

    r3302 r3304  
    11211121  std::vector<MBEntityHandle>::iterator adj_it, w_it; 
    11221122  MBErrorCode result = MB_SUCCESS; 
     1123   
     1124  if (begin == end) { 
     1125    adj_entities.clear(); // intersection 
     1126    return MB_SUCCESS; 
     1127  } 
     1128   
     1129    // First iteration is a special case if input list is empty. 
     1130    // Rather than returning nothing (intersecting with empty 
     1131    // input list), we begin with the adjacencies for the first entity. 
     1132  if (adj_entities.empty()) { 
     1133    MBEntityType type = TYPE_FROM_HANDLE(*begin); 
     1134    if (to_dimension == MBCN::Dimension(type))  
     1135      adj_entities.push_back(*begin);  
     1136    else if(to_dimension == 0 && type != MBPOLYHEDRON) 
     1137      result = mb->get_connectivity(&(*begin), 1, adj_entities); 
     1138    else 
     1139      result = mb->a_entity_factory()->get_adjacencies(*begin, to_dimension,  
     1140                                                   create_if_missing, adj_entities); 
     1141    if (MB_SUCCESS != result) 
     1142      return result; 
     1143    ++begin; 
     1144  } 
    11231145 
    11241146  for (ITER from_it = begin; from_it != end; from_it++)  
     
    11391161      return result; 
    11401162   
    1141       // If first iteration and input is empty, begin with first set of adjacencies 
    1142     if (from_it == begin && adj_entities.empty()) { 
    1143       adj_entities.swap( temp_vec ); 
    1144       continue; 
    1145     } 
    1146    
    11471163      // otherwise intersect with the current set of results 
    11481164    w_it = adj_it = adj_entities.begin(); 
     
    12031219                                     const int operation_type ) 
    12041220{ 
    1205   MBErrorCode result; 
    1206   if (num_entities == 1 && adj_entities.empty()) { 
    1207     if(to_dimension == 0 && TYPE_FROM_HANDLE(from_entities[0]) != MBPOLYHEDRON) 
    1208       result = get_connectivity(&from_entities[0], 1, adj_entities); 
    1209     else 
    1210       result = aEntityFactory->get_adjacencies(from_entities[0], to_dimension,  
    1211                                              create_if_missing, adj_entities); 
    1212      
    1213     //adj_entities.erase( std::remove( adj_entities.begin(), adj_entities.end(), 0 ), adj_entities.end() ); 
    1214     return result; 
    1215   } 
    1216   else if (operation_type == MBInterface::INTERSECT) 
     1221  if (operation_type == MBInterface::INTERSECT) 
    12171222    return get_adjacencies_intersection( this, from_entities, from_entities+num_entities,  
    12181223                                         to_dimension, create_if_missing, adj_entities ); 
     
    12211226     
    12221227    // do union 
     1228  MBErrorCode result; 
    12231229  std::vector<MBEntityHandle> tmp_storage; 
    12241230  const MBEntityHandle* conn;