From 726590ed5f3ac23f8316ed3988bf24f87ff58360 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 27 Apr 2023 10:13:39 -0600 Subject: [PATCH] [gvar] Add optimize-size code path --- src/hb-ot-var-gvar-table.hh | 100 +++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 5d9663c41..23b308175 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -368,50 +368,78 @@ struct gvar hb_memset (deltas.arrayZ, 0, deltas.get_size ()); } - /* Ouch. Four cases... for optimization. */ - if (scalar != 1.0f) + bool optimize_size = +#ifdef HB_OPTIMIZE_SIZE + true +#else + false +#endif + ; + if (optimize_size) { - if (apply_to_all) - for (unsigned int i = 0; i < num_deltas; i++) + for (unsigned int i = 0; i < num_deltas; i++) + { + unsigned int pt_index; + if (apply_to_all) + pt_index = i; + else { - unsigned int pt_index = i; - auto &delta = deltas.arrayZ[pt_index]; - delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ - delta.x += x_deltas.arrayZ[i] * scalar; - delta.y += y_deltas.arrayZ[i] * scalar; - } - else - for (unsigned int i = 0; i < num_deltas; i++) - { - unsigned int pt_index = indices[i]; + pt_index = indices[i]; if (unlikely (pt_index >= deltas.length)) continue; - auto &delta = deltas.arrayZ[pt_index]; - delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ - delta.x += x_deltas.arrayZ[i] * scalar; - delta.y += y_deltas.arrayZ[i] * scalar; } + auto &delta = deltas.arrayZ[pt_index]; + delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ + delta.x += x_deltas.arrayZ[i] * scalar; + delta.y += y_deltas.arrayZ[i] * scalar; + } } else { - if (apply_to_all) - for (unsigned int i = 0; i < num_deltas; i++) - { - unsigned int pt_index = i; - auto &delta = deltas.arrayZ[pt_index]; - delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ - delta.x += x_deltas.arrayZ[i]; - delta.y += y_deltas.arrayZ[i]; - } + /* Ouch. Four cases... for optimization. */ + if (scalar != 1.0f) + { + if (apply_to_all) + for (unsigned int i = 0; i < num_deltas; i++) + { + unsigned int pt_index = i; + auto &delta = deltas.arrayZ[pt_index]; + delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ + delta.x += x_deltas.arrayZ[i] * scalar; + delta.y += y_deltas.arrayZ[i] * scalar; + } + else + for (unsigned int i = 0; i < num_deltas; i++) + { + unsigned int pt_index = indices[i]; + if (unlikely (pt_index >= deltas.length)) continue; + auto &delta = deltas.arrayZ[pt_index]; + delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ + delta.x += x_deltas.arrayZ[i] * scalar; + delta.y += y_deltas.arrayZ[i] * scalar; + } + } else - for (unsigned int i = 0; i < num_deltas; i++) - { - unsigned int pt_index = indices[i]; - if (unlikely (pt_index >= deltas.length)) continue; - auto &delta = deltas.arrayZ[pt_index]; - delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ - delta.x += x_deltas.arrayZ[i]; - delta.y += y_deltas.arrayZ[i]; - } + { + if (apply_to_all) + for (unsigned int i = 0; i < num_deltas; i++) + { + unsigned int pt_index = i; + auto &delta = deltas.arrayZ[pt_index]; + delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ + delta.x += x_deltas.arrayZ[i]; + delta.y += y_deltas.arrayZ[i]; + } + else + for (unsigned int i = 0; i < num_deltas; i++) + { + unsigned int pt_index = indices[i]; + if (unlikely (pt_index >= deltas.length)) continue; + auto &delta = deltas.arrayZ[pt_index]; + delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ + delta.x += x_deltas.arrayZ[i]; + delta.y += y_deltas.arrayZ[i]; + } + } } /* infer deltas for unreferenced points */