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

@ -330,6 +330,62 @@ static void test_fuzz(int index, int debug) {
testFinish();
}
static char TeleTable[128][16] = {
{ "31313131" }, { "1131313111" }, { "33313111" }, { "1111313131" },
{ "3111313111" }, { "11333131" }, { "13133131" }, { "111111313111" },
{ "31333111" }, { "1131113131" }, { "33113131" }, { "1111333111" },
{ "3111113131" }, { "1113133111" }, { "1311133111" }, { "111111113131" },
{ "3131113111" }, { "11313331" }, { "333331" }, { "111131113111" },
{ "31113331" }, { "1133113111" }, { "1313113111" }, { "1111113331" },
{ "31131331" }, { "113111113111" }, { "3311113111" }, { "1111131331" },
{ "311111113111" }, { "1113111331" }, { "1311111331" }, { "11111111113111" },
{ "31313311" }, { "1131311131" }, { "33311131" }, { "1111313311" },
{ "3111311131" }, { "11333311" }, { "13133311" }, { "111111311131" },
{ "31331131" }, { "1131113311" }, { "33113311" }, { "1111331131" },
{ "3111113311" }, { "1113131131" }, { "1311131131" }, { "111111113311" },
{ "3131111131" }, { "1131131311" }, { "33131311" }, { "111131111131" },
{ "3111131311" }, { "1133111131" }, { "1313111131" }, { "111111131311" },
{ "3113111311" }, { "113111111131" }, { "3311111131" }, { "111113111311" },
{ "311111111131" }, { "111311111311" }, { "131111111311" }, { "11111111111131" },
{ "3131311111" }, { "11313133" }, { "333133" }, { "111131311111" },
{ "31113133" }, { "1133311111" }, { "1313311111" }, { "1111113133" },
{ "313333" }, { "113111311111" }, { "3311311111" }, { "11113333" },
{ "311111311111" }, { "11131333" }, { "13111333" }, { "11111111311111" },
{ "31311133" }, { "1131331111" }, { "33331111" }, { "1111311133" },
{ "3111331111" }, { "11331133" }, { "13131133" }, { "111111331111" },
{ "3113131111" }, { "1131111133" }, { "33111133" }, { "111113131111" },
{ "3111111133" }, { "111311131111" }, { "131111131111" }, { "111111111133" },
{ "31311313" }, { "113131111111" }, { "3331111111" }, { "1111311313" },
{ "311131111111" }, { "11331313" }, { "13131313" }, { "11111131111111" },
{ "3133111111" }, { "1131111313" }, { "33111313" }, { "111133111111" },
{ "3111111313" }, { "111313111111" }, { "131113111111" }, { "111111111313" },
{ "313111111111" }, { "1131131113" }, { "33131113" }, { "11113111111111" },
{ "3111131113" }, { "113311111111" }, { "131311111111" }, { "111111131113" },
{ "3113111113" }, { "11311111111111" }, { "331111111111" }, { "111113111113" },
{ "31111111111111" }, { "111311111113" }, { "131111111113" },
{'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
};
// Dummy to generate lengths table
static void test_generate_lens(int generate) {
int i;
if (!generate) {
return;
}
printf("static const char TeleLens[128] = {");
for (i = 0; i < 127; i++) {
if ((i % 16) == 0) {
printf("\n %2d,", (int) strlen(TeleTable[i]));
} else {
printf(" %2d,", (int) strlen(TeleTable[i]));
}
}
printf(" 16\n};\n");
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
@ -338,6 +394,7 @@ int main(int argc, char *argv[]) {
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_generate_lens", test_generate_lens, 0, 1, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));