initialization lists

Thanks for releasing b2d 2.2! I've already integrated it into my project and I can't wait to check out the new features. I've been using b2d for a few years now and I love it.

One tiny suggestion I have is to use constructor initialization lists, even for structs. For example:

Code:
b2Filter::b2Filter() :
  categoryBits(0x0),
  maskBits(0x0),
  groupIndex(0)
{

}


It's faster than setting that variables in the body of the constructor or by a creating class because the init list commands occur as the memory for the variables is allocated, rather than after.

More importantly, using them can avoid bugs. For example, b2Filter's members are usually set during b2d helper functions or convenience calls, but when you create a filter manually they are not. This created some strange bugs for me that were difficult to track down. I assumed that the members of the filter would always have the same values when constructed, but without an init list, the default values of the members were undefined and would change from run to run.

Thanks again!

---
Paul, Riverman Media
http://www.rivermanmedia.com
Initialization lists are only faster when members have non-trivial constructors. In this case they do not. Also, initialization lists are error prone because they are not executed in the order you write them, but in the order of the members. So I would only use an initialization list if I had a member with an expensive default constructor and I needed to call a non-default constructor - a very rare case.

I'm fine with adding a constructor for b2Filter to set default values. However, some structures, such as b2Vec2, should not have default initialization because of the performance hit. I filed an issue here: http://code.google.com/p/box2d/issues/detail?id=237
Cool, thanks for getting back to me so fast.

Original thread: https://box2d.org/forum/viewtopic.php?t=7564