This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/32618] std::vector calls uneccessary constructors instead of inplace construction of first object



------- Comment #3 from oliver at kfs dot org  2007-07-04 04:27 -------
Andrew, currently it seems to work like this (pseudo code warning):

  T* newSpace = alloc(newSize);
  int i = 0 ;
  for ( ; i < size ; ++i ) {
   newSpace[i].constructor(oldSpace[i]) ;
  }

  const T defaultInstance ;

  for ( ; i < newSize ; i++ ) {
   newSpace[i].constructor(defaultInstance) ;
  }

What I'm talking about is replacing "const T defaultInstance;" with

  // Execute the default constructor on the first new element
  newSpace[i].constructor() ;
  // Take a reference to this object for copying to subsequent instances
  const T& defaultInstance = newSpace[i] ;
  // Advance i to the next element
  ++i ;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32618


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]