minimize getDataLength() calls