Commit e24274bb authored by vaclav's avatar vaclav
Browse files

Merge branch '520-remove-memmove-from-jbm-code' into 'main'

Resolve "Remove memmove from JBM code"

See merge request !1148
parents 9bf9f6f2 694aa517
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@
#define FIX_854_ARRAY_SIZE_MISMATCH                     /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */
#define FIX_785_REMOVE_DEAD_CODE                        /* VA: issue 785: remove dead code */
#define FIX_852_FIX_HANDLE_DEREF                        /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */
#define FIX_520_REMOVE_MEMMOVE_JBM                      /* VA: issue 520: Remove memmove() from JBM code */


/* #################### End BE switches ################################## */
+21 −3
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@
 * @param[in,out] size size of elements buffer
 * @param[in]     capacity maximum number of elements to buffer
 * @param[in]     newElement element to insert in buffer if great enough */
static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, uint16_t *size, uint16_t capacity, JB4_CIRCULARBUFFER_ELEMENT newElement );
static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, uint16_t *size, const uint16_t capacity, JB4_CIRCULARBUFFER_ELEMENT newElement );

/** circular buffer (FIFO) with fixed capacity */
struct JB4_CIRCULARBUFFER
@@ -70,7 +70,8 @@ struct JB4_CIRCULARBUFFER


/* Creates a circular buffer (FIFO) */
ivas_error JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph )
ivas_error JB4_CIRCULARBUFFER_Create(
    JB4_CIRCULARBUFFER_HANDLE *ph )
{
    JB4_CIRCULARBUFFER_HANDLE h;

@@ -433,10 +434,13 @@ void JB4_CIRCULARBUFFER_MinAndPercentile(
static void JB4_CIRCULARBUFFER_calcPercentile(
    JB4_CIRCULARBUFFER_ELEMENT *elements,
    uint16_t *size,
    uint16_t capacity,
    const uint16_t capacity,
    JB4_CIRCULARBUFFER_ELEMENT newElement )
{
    uint16_t i;
#ifdef FIX_520_REMOVE_MEMMOVE_JBM
    uint16_t j;
#endif

    /* insert newElement if elements buffer is not yet full */
    if ( *size < capacity )
@@ -446,7 +450,14 @@ static void JB4_CIRCULARBUFFER_calcPercentile(
            if ( newElement <= elements[i] )
            {
                /* insert newElement at index i */
#ifdef FIX_520_REMOVE_MEMMOVE_JBM
                for ( j = *size; j > i; --j )
                {
                    elements[j] = elements[j - 1];
                }
#else
                memmove( elements + i + 1, elements + i, ( *size - i ) * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); /* IVAS_fmToDo: avoid use of memmove() */
#endif
                elements[i] = newElement;
                ++*size;
                return;
@@ -470,7 +481,14 @@ static void JB4_CIRCULARBUFFER_calcPercentile(
        if ( newElement >= elements[i] )
        {
            /* insert newElement at index i */
#ifdef FIX_520_REMOVE_MEMMOVE_JBM
            for ( j = 0; j < i; j++ )
            {
                elements[j] = elements[1 + j];
            }
#else
            memmove( elements, elements + 1, i * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) );
#endif
            elements[i] = newElement;
            return;
        }
+20 −1
Original line number Diff line number Diff line
@@ -151,6 +151,9 @@ int16_t JB4_INPUTBUFFER_Enque(
    uint16_t canMoveRight;
    uint16_t canMoveLeft;
    bool replace;
#ifdef FIX_520_REMOVE_MEMMOVE_JBM
    uint16_t j;
#endif
    *replacedElement = NULL;

    size = JB4_INPUTBUFFER_Size( h );
@@ -210,12 +213,14 @@ int16_t JB4_INPUTBUFFER_Enque(
        }
    }

#ifdef DEBUGGING
    assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low ), &replace ) != 0 );
    if ( low > 0 )
        assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low - 1 ), &replace ) > 0 );
    assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low ), &replace ) < 0 );
    if ( (uint16_t) ( low + 1 ) < size )
        assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low + 1 ), &replace ) < 0 );
#endif

    insertPos = ( h->readPos + low ) % h->capacity;
    if ( h->readPos < h->writePos )
@@ -234,7 +239,14 @@ int16_t JB4_INPUTBUFFER_Enque(
    if ( canMoveRight )
    {
        /* move higher elements to the right and insert at insertPos */
#ifdef FIX_520_REMOVE_MEMMOVE_JBM
        for ( j = h->writePos; j > insertPos; --j )
        {
            h->data[j] = h->data[j - 1];
        }
#else
        memmove( h->data + insertPos + 1, h->data + insertPos, ( h->writePos - insertPos ) * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); /* IVAS_fmToDo: avoid use of memmove() */
#endif
        h->data[insertPos] = element;
        ++h->writePos;
        if ( h->writePos == h->capacity )
@@ -245,7 +257,14 @@ int16_t JB4_INPUTBUFFER_Enque(
    else
    {
        /* move lower elements to the left and insert before insertPos */
#ifdef FIX_520_REMOVE_MEMMOVE_JBM
        for ( j = 0; j < low; j++ )
        {
            h->data[h->readPos - 1 + j] = h->data[h->readPos + j];
        }
#else
        memmove( h->data + h->readPos - 1, h->data + h->readPos, low * sizeof( JB4_INPUTBUFFER_ELEMENT ) );                       /* IVAS_fmToDo: avoid use of memmove() */
#endif
        h->data[insertPos - 1] = element;
        --h->readPos;
        assert( (int16_t) h->readPos >= 0 );