From c693ec0a3d6d6595473c603b8f6a9bc3711dd001 Mon Sep 17 00:00:00 2001 From: David Declerck Date: Thu, 26 Sep 2024 18:09:37 +0200 Subject: [PATCH] Merge SVN 4991 --- libcob/ChangeLog | 6 ++++++ libcob/numeric.c | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libcob/ChangeLog b/libcob/ChangeLog index e2b49dfe7..faa87cc53 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -92,6 +92,12 @@ * numeric.c: Changes to speed up COMP-3 handling +2023-02-21 Simon Sobisch + + * numeric.c (cob_decimal_set_packed): backport and extend optimization + from 4.x by Ron - now skipping initial zeros and for huge fields handle + 4 digits at once + 2023-02-20 Simon Sobisch * intrinsic.c, numeric.c: explicit check result of mpz_sgn to 0/!0/1/-1 diff --git a/libcob/numeric.c b/libcob/numeric.c index 4d57cef76..28be63398 100644 --- a/libcob/numeric.c +++ b/libcob/numeric.c @@ -1038,8 +1038,22 @@ cob_decimal_set_packed (cob_decimal *d, cob_field *f) digits = COB_FIELD_DIGITS (f); if (digits % 2 == nibtest) { byteval = *p++ & 0x0F; + if (byteval == 0) { + /* Skip leading ZEROs */ + while (p < endp + && *p == 0x00) { + digits -= 2; + p++; + } + } } else { byteval = 0; + /* Skip leading ZEROs */ + while (p < endp + && *p == 0x00) { + digits -= 2; + p++; + } } if (byteval == 0) { while (p < endp @@ -2746,9 +2760,7 @@ insert_packed_aligned ( *(ptr_byte1 + len1 - 1) &= 0xF0; /* clear sign nibble */ } - if (nibble_cntr == 0) { - compare_len = len1 + byte_cntr; - } else { + if (nibble_cntr != 0) { /* shift the complete filled buffer one nibble left */ #ifdef ALTERNATIVE_PACKED_SWAP /* should work portably, but is around 20% slower */ @@ -2798,6 +2810,8 @@ insert_packed_aligned ( #endif compare_len = len1 + byte_cntr + nibble_cntr; + } else { + compare_len = len1 + byte_cntr; } /* insert data2 into initialized buffer at the end */