- for (unsigned i = 0; i < num && cost < best_cost; ++i) {
- unsigned val = in[i] >> test_bit_width;
- if (val == 0) {
- // Not stored, and then also no index.
- } else if (val <= 176) {
- cost += 2;
- } else if (val <= 16560) {
- cost += 3;
- } else if (val <= 540848) {
- cost += 4;
- } else if (val <= 16777215) {
- cost += 5;
- } else {
- cost += 6;
+ if (cost >= best_cost) {
+ break;
+ }
+ if (test_bit_width + 1 <= max_bits) {
+ cost += 2 * histogram[test_bit_width + 1]; // > 0.
+ if (test_bit_width + 7 <= max_bits) {
+ cost += histogram[test_bit_width + 7]; // > 176, very roughly.
+ if (test_bit_width + 14 <= max_bits) {
+ cost += histogram[test_bit_width + 14]; // > 16560, very roughly.
+ if (test_bit_width + 19 <= max_bits) {
+ cost += histogram[test_bit_width + 19]; // > 540848, very roughly.
+ if (test_bit_width + 24 <= max_bits) {
+ cost += histogram[test_bit_width + 24]; // > 16777215, very roughly.
+ }
+ }
+ }