Further optimize C++ entropy computation