TH: fix speed issue due to calls to THTensor_nElement()