Performance improvements for linear encoding and raster output

- use fixed-length string tables (mostly) instead of (char *) pointer ones
   (saves ~40K)
 - re-use C128Table for CODABLOCKF and CODE16K
   (required removal of Stop character and extra CODE16K-only entry)
 - use pointer to destination and copy (memcpy/strcpy(), bin_append_posn())
   instead of concatenating (strcat()) (mostly)
 - replace last remaining bin_append()s with bin_append_posn();
   bin_append() removed
 - add length arg to toupper() and expand() (avoids strlen())
 - change is_sane() to use table-based flags (avoids an iteration)
 - rename lookup() to is_sane_lookup() and change to check and return posns
   and use in pointer to destination loops (avoids strcat()s)
 - remove special case PHARMA in expand() (dealt with in pharma())
 - make #define SILVER/CALCIUM/TECHNETIUM/KRSET etc static strings
 - replace strchr() -> posn()
 - CODE128: populate destination once in checksum loop; re-use and export
   some more routines (c128_set_a/b/c(), c128_put_in_set()) for sharing;
   prefix defines (SHIFTA -> C128_SHIFTA etc) and existing exported routines
 - use factor XOR toggle trick in checksum calcs (avoids branch)
 - raster.c: fill out single 1-pixel row and copy using new draw_bar_line(),
   copy_bar_line() routines; similarly in buffer_plot compare previous line &
   copy if same (same technique as used to improve non-half-integer scaling,
   significant performance increase, (c) codemonkey82);
   also done for PNG (BMP/GIF/PCX/TIFF not done)
 - raster/vector/output.c: shorten "output_" prefix -> "out_";
   sync vector to other raster changes to try to keep source files similar
 - 2of5.c: prefix "c25_"
JAPANPOST: return error if input data truncated (backward incompatible)
DAFT: max chars 50 -> 100
common.c: istwodigit() -> is_twodigit()
common.c/emf.c/output.c: use some further stripf()s (MSVC6 float variations)
library.c: new check_output_args() helper
zint.h: add BARCODE_LAST marker and use in library.c
QRCODE: remove a NOLINT (requires clang-tidy-13), one remaining
CMake: separate no-optimize from ZINT_DEBUG into new ZINT_NOOPT option
This commit is contained in:
gitlost 2021-10-20 23:05:30 +01:00
parent e8b59aa696
commit fab7435fac
72 changed files with 3501 additions and 2380 deletions

View file

@ -52,7 +52,7 @@ static int numeric(const unsigned char *data, int data_len, int offset, int min,
if (data_len) {
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len);
const unsigned char *const de = d + (data_len > max ? max : data_len);
for (; d < de; d++) {
if (*d < '0' || *d > '9') {
@ -90,7 +90,7 @@ static int cset82(const unsigned char *data, int data_len, int offset, int min,
if (data_len) {
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len);
const unsigned char *const de = d + (data_len > max ? max : data_len);
for (; d < de; d++) {
if (*d < '!' || *d > 'z' || c82[*d - '!'] == 82) {
@ -117,7 +117,7 @@ static int cset39(const unsigned char *data, int data_len, int offset, int min,
if (data_len) {
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len);
const unsigned char *const de = d + (data_len > max ? max : data_len);
for (; d < de; d++) {
/* 0-9, A-Z and "#", "-", "/" */
@ -145,13 +145,13 @@ static int csum(const unsigned char *data, int data_len, int offset, int min, in
if (!length_only && data_len) {
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len) - 1; /* Note less last character */
const unsigned char *const de = d + (data_len > max ? max : data_len) - 1; /* Note less last character */
int checksum = 0;
int factor = (min & 1) ? 1 : 3;
for (; d < de; d++) {
checksum += (*d - '0') * factor;
factor = factor == 3 ? 1 : 3;
factor ^= 2; /* Toggles 1 and 3 */
}
checksum = 10 - checksum % 10;
if (checksum == 10) {
@ -189,7 +189,7 @@ static int csumalpha(const unsigned char *data, int data_len, int offset, int mi
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83
};
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len) - 2; /* Note less last 2 characters */
const unsigned char *const de = d + (data_len > max ? max : data_len) - 2; /* Note less last 2 characters */
int checksum = 0, c1, c2;
for (; d < de; d++) {
@ -549,7 +549,7 @@ static int pcenc(const unsigned char *data, int data_len, int offset, int min, i
if (!length_only && data_len) {
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len);
const unsigned char *const de = d + (data_len > max ? max : data_len);
for (; d < de; d++) {
if (*d == '%') {
@ -746,7 +746,7 @@ static int iban(const unsigned char *data, int data_len, int offset, int min, in
if (!length_only && data_len) {
const unsigned char *d = data + offset;
const unsigned char *de = d + (data_len > max ? max : data_len);
const unsigned char *const de = d + (data_len > max ? max : data_len);
int checksum = 0;
int given_checksum;
@ -1394,7 +1394,7 @@ INTERNAL char gs1_check_digit(const unsigned char source[], const int length) {
for (i = 0; i < length; i++) {
count += factor * ctoi(source[i]);
factor = factor == 1 ? 3 : 1;
factor ^= 2; /* Toggles 1 and 3 */
}
return itoc((10 - (count % 10)) % 10);